Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific database for write operations in multi-DB setup #124

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

Nathan-Cohen
Copy link
Contributor


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

  • I have performed a self-review of my code.
  • [NA] I have added tests for the proposed changes.
  • [NA] I have run the tests and there are not errors.

Summary:

This PR introduces modifications to enhance support for write operations in environments utilizing multiple databases. The modifications ensure that the update_tree and delete_tree methods in the models.py file direct their write operations to the correct database as specified by the database router's db_for_write method.

Changes Made:

  1. update_tree Method:

    • The method has been modified to use the database specified for write operations by the database router.
    • The using argument in transaction.atomic() is employed as transaction.atomic(using=router.db_for_write(TreeNodeModel)).
  2. delete_tree Method:

    • The method has been similarly modified to ensure correct routing of write operations to the appropriate database.

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 and delete_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.

@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (dc9e265) 90.42% compared to head (a672eaf) 90.42%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #124   +/-   ##
=======================================
  Coverage   90.42%   90.42%           
=======================================
  Files          10       10           
  Lines         658      658           
=======================================
  Hits          595      595           
  Misses         63       63           
Flag Coverage Δ
unittests 90.42% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
treenode/models.py 97.88% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabiocaccamo fabiocaccamo merged commit c121415 into fabiocaccamo:main Sep 26, 2023
@fabiocaccamo fabiocaccamo self-requested a review September 26, 2023 13:52
@fabiocaccamo fabiocaccamo added the bug Something isn't working label Sep 26, 2023
@fabiocaccamo
Copy link
Owner

@Nathan-Cohen thank you very much, I will release a patch release as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants