Use specific database for write operations in multi-DB setup #124
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.
name: Pull request
about: Submit a pull request for this project
assignees: fabiocaccamo
Related issue
Database Configuration error in update_tree #123
Checklist before requesting a review
Summary:
This PR introduces modifications to enhance support for write operations in environments utilizing multiple databases. The modifications ensure that the
update_tree
anddelete_tree
methods in themodels.py
file direct their write operations to the correct database as specified by the database router'sdb_for_write
method.Changes Made:
update_tree
Method:using
argument intransaction.atomic()
is employed astransaction.atomic(using=router.db_for_write(TreeNodeModel))
.delete_tree
Method:Rationale:
In projects utilizing multiple databases, it is essential to direct write operations to the appropriate database reliably. The modifications in this PR address this need by explicitly specifying the database for write operations in
update_tree
anddelete_tree
methods, contributing to the overall stability and reliability of the package in multi-database environments.Regarding Testing
Wanted to throw in some tests for these changes, but that would need a bit of a setup overhaul to simulate multiple databases – seemed a bit overkill for this PR.
Did run manual checks to ensure everything’s in order. I believe the changes shouldn’t mess with the library’s flow and should be a plus for those juggling multiple databases.