Remove redundant refresh following the update procedure #154
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.