Commit 48f9809
authored
fix(mass_model_updater): read tracked fields via attribute access for skip_unchanged (#15114)
The skip-unchanged no-op check snapshotted each tracked field with
model.__dict__.get(f) to avoid triggering a deferred-field load. But when a
tracked field is deferred (the caller's queryset used .only()/.defer() and
omitted it), __dict__ has no entry and .get() returns None. If function then
recomputes that field to None, None == None marks the row unchanged and the
write is silently dropped, persisting a stale value.
Read the pre-function value with normal attribute access (getattr) instead.
Deferred tracked fields are loaded and compared against their real persisted
value, so a real change can never be mistaken for a no-op. The cost of a
deferred tracked field is now a visible per-row load rather than silent data
loss; callers needing the fast path must load the tracked fields in their
queryset (documented).
Adds regression tests: a deferred tracked field recomputed to None must issue
an UPDATE and persist; one left unchanged must still skip the write.1 parent 5e4c8d8 commit 48f9809
2 files changed
Lines changed: 57 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1646 | 1646 | | |
1647 | 1647 | | |
1648 | 1648 | | |
1649 | | - | |
1650 | | - | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
1651 | 1653 | | |
1652 | 1654 | | |
1653 | 1655 | | |
| |||
1689 | 1691 | | |
1690 | 1692 | | |
1691 | 1693 | | |
1692 | | - | |
1693 | | - | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
1694 | 1697 | | |
1695 | 1698 | | |
1696 | | - | |
| 1699 | + | |
1697 | 1700 | | |
1698 | 1701 | | |
1699 | 1702 | | |
1700 | 1703 | | |
1701 | | - | |
| 1704 | + | |
1702 | 1705 | | |
1703 | 1706 | | |
1704 | 1707 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
133 | 181 | | |
134 | 182 | | |
135 | 183 | | |
| |||
0 commit comments