-
Notifications
You must be signed in to change notification settings - Fork 420
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
enable use of replica database #359
Conversation
When you use replica database the django-auditlog try to write in the same database where object was read (replica). But this is a read only database and crash the application. This changes saves always in the default database. If you want to save in multiple databases or in a special one use `DATABASE_ROUTERS` to configure it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
important feature for reading bank
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very usefull I can't imagine why we don't use this yet.
Usefull for amazon rds writer/reader databases. |
Codecov Report
@@ Coverage Diff @@
## master #359 +/- ##
==========================================
+ Coverage 82.41% 82.57% +0.16%
==========================================
Files 20 20
Lines 506 505 -1
==========================================
Hits 417 417
+ Misses 89 88 -1
Continue to review full report at Codecov.
|
PSC @Linkid any thoughts? |
be4467f
@hramezani Thanks a lot for the review. I just made the changes you suggested. Please check everything is ok to merge with master. |
CHANGELOG.md
Outdated
@@ -6,6 +6,7 @@ | |||
|
|||
#### Improvements | |||
|
|||
- feat: enable use of replica database (delegating the choice to `DATABASES_ROUTER`) ([#359](https://github.com/jazzband/django-auditlog/pull/359)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please place in a new section above because this section belongs to the already released version 1.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please mention LogEntry no longer save to same database instance is using
auditlog_tests/tests.py
Outdated
@@ -920,3 +923,31 @@ def test_no_delete_related(self): | |||
list(entries.values_list("action", flat=True)), | |||
[LogEntry.Action.CREATE, LogEntry.Action.UPDATE, LogEntry.Action.DELETE], | |||
) | |||
|
|||
|
|||
class ModelFromDifferentDatabase(TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need a new class, you can add this test to
django-auditlog/auditlog_tests/tests.py
Line 36 in 665217d
class SimpleModelTest(TestCase): |
auditlog_tests/tests.py
Outdated
changes=json.dumps(changes), | ||
) | ||
self.assertEqual(log_entry._state.db, "default", msg=msg) # must be created in default database | ||
except ConnectionDoesNotExist as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this except block?
Please take a look at failing tests as well. |
@hramezani thank you again. I have updated all the points you suggested All tests are working fine. |
Thanks @fgsamuel I will take a look again next week |
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* master: Remove default_app_config configuration Fix lint entry in tox.ini Drop Django 2.2 support. [pre-commit.ci] pre-commit autoupdate Fix small typo Add mask_fields argument in register (jazzband#310) Use pre-commit as lint command Add black and isort to .pre-commit-config.yaml Replace assertTrue with assertEqual enable use of replica database (jazzband#359)
When you use replica database the django-auditlog try to write in the same database where object was read (replica). But this is a read only database and crash the application.
With this changes it saves always in the default database.
If you want to save in multiple databases or in a special one use
DATABASE_ROUTERS
to configure it.To continue using multiple databases, you must configure it in your DATABASE ROUTERS.