Commit 4b4d61c
fix: restore falling back to current document values for
### What?
**Behavior prior to this change:**
When restoring a version, `beforeValidate` field processing backfilled
`undefined` fields from the current document data into the
to-be-restored document data. This behavior is correct for partial
updates (preserving unmodified fields), but incorrect for restore
operations, where the version snapshot is the complete desired state.
This is the current behavior on `main`: Note how the `Radio` field is
not set in the first version, but set to `Test en` after the restore of
said first version.
https://github.com/user-attachments/assets/56467956-7caa-4363-989e-bcd1a663ce7a
**Behavior with this change:**
The desired fallback behavior during partial updates is retained, but
the to-be-restored document no longer runs this fallback behavior. The
restored document equals the document that the user triggered the
restore for.
Note how now the `Radio` field is not set again after the restore, just
like it was when the first version was created:
https://github.com/user-attachments/assets/0b5833b5-3694-4b10-9a11-f25f5c1a3b24
### Why?
When a user restores an old document version, the user's expectation is
that the old document is what they are going to get after successful
restore. It is unexpected if the document is a "frankenstein" version of
the old document and the current document, especially since the user has
no way to see the resulting document before the restore and can't know
which attributes might be set from the current document as fallback
value.
### How?
`getFallbackValue` is skipped during restore operations denoted with the
new request context `isRestoringVersion = true`.
---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
- https://app.asana.com/0/0/1214068985579207
---------
Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>undefined fields (#16272)1 parent cb97614 commit 4b4d61c
4 files changed
Lines changed: 74 additions & 2 deletions
File tree
- packages/payload/src
- collections/operations
- fields/hooks/beforeValidate
- globals/operations
- test/versions
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
| 281 | + | |
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
787 | 855 | | |
788 | 856 | | |
789 | 857 | | |
| |||
0 commit comments