Remove redundant refresh following the update procedure#154
Remove redundant refresh following the update procedure#154radicalbiscuit wants to merge 1 commit intobeda-software:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #154 +/- ##
==========================================
- Coverage 98.18% 98.17% -0.01%
==========================================
Files 3 3
Lines 220 219 -1
==========================================
- Hits 216 215 -1
Misses 4 4
Continue to review full report at Codecov.
|
|
Hi @pcarn Sorry for bothering you. I hope you are doing well and could help us here. The code that does the same thing on the DRF level mentioned by @radicalbiscuit was added 5 years ago. However, the merge request contains tests and tests passed for this pull request. @pcarn Is it possible for you to check if your code still working when you remove https://github.com/beda-software/drf-writable-nested/blob/master/drf_writable_nested/mixins.py#L291 Best, |
We use a read replica database in our deployment. As such, there is some nonzero replication lag between the write DB and the read replica DB. Because
NestedUpdateMixin.update()performsinstance.refresh_from_db()immediately following the write operations, we sometimes get stale data from the refresh.Stepping through the code, I found that (in all our usages, anyway) the refresh was redundant. The nested objects are all updated independently and then reattached to parent objects as part of vanilla DRF, making the refresh operation superfluous.
One possible risk I may have not accounted for is many-to-many relations. I don't think our specific use case encounters those.
If this solution is unacceptable, please let me know and I'll rework it into an instance attribute or method kwarg that will either direct drf-writable-nested which database to use in making its read immediately following the write or whether to electively skip the refresh entirely. Currently, our solution is to monkey patch, which we'd like to avoid. Also, if it would be better to go through a formal Issue process first, let me know. I'm very grateful for your work and contribution here. It has saved me a lot of time and heartache.