-
-
Notifications
You must be signed in to change notification settings - Fork 193
Respect 'using' in signals #200
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
Conversation
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.
Could you add also a test to this PR please?
tests/test_models.py
Outdated
theme_1 = Theme.objects.create(name="Custom 1", active=True) | ||
kwargs = {"db" : "default"} | ||
Theme.get_active_theme(**kwargs) | ||
|
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.
This test is ok, but I think it would have passed the tests even before the other changes you made because it uses the default database. Could you add also another that uses another database please?
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.
Just added another test for failure when passing an invalid DB parameter. I'll need to change some of the settings if you'd prefer a multi-db test as well
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.
If you could add a third test for multi-db it would be great!
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.
Done!
@merwok the CI |
None of my changes touch anything regarding translations so I'm not sure where it arises. Do you have an idea what could be the cause? That'll help me start digging |
tests/test_models.py
Outdated
theme_1 = Theme.objects.create(name="Custom 1", active=True) | ||
kwargs = {"db" : "default"} | ||
Theme.get_active_theme(**kwargs) | ||
|
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.
If you could add a third test for multi-db it would be great!
@VaZark please update this branch from master, I have updated the test workflow for running tests even if the |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
admin_interface/models.py
Outdated
Theme.get_active_theme() | ||
objs_manager = Theme.objects | ||
if "using" in kwargs: | ||
objs_manager = objs_manager.using(kwargs["using"]) |
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.
This condition could be avoided by just doing:
objs_database = kwargs.get("using", "default")
objs_manager = Theme.objects.using(objs_database)
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.
Since I'll be replacing *args, **kwargs
could be replaced by database="default", that can replace the
kwargs.get`. Will still be removing the if check.
admin_interface/models.py
Outdated
@@ -42,8 +46,10 @@ def pre_save_handler(instance, **kwargs): | |||
pass | |||
|
|||
@staticmethod | |||
def get_active_theme(): | |||
def get_active_theme(*args, **kwargs): |
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.
We don't need *args
here, and **kwargs
could be replaced by database="default"
.
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.
okay. I'll update all the references in the model to use database
No, I don't understand the cause, for this reason I updated the test workflow. |
Codecov ReportBase: 95.55% // Head: 95.58% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #200 +/- ##
==========================================
+ Coverage 95.55% 95.58% +0.03%
==========================================
Files 36 36
Lines 405 408 +3
==========================================
+ Hits 387 390 +3
Misses 18 18
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@VaZark tests are broken with postgres. |
The pg tests were broken due to HOST and port not being set for |
|
||
@classmethod | ||
def setUpTestData(cls): | ||
Theme.objects.using("default").create(name="Change Active", active=True) |
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.
using("default")
could be omitted here.
Great changes here! The reason for the lint failure can be seen in the CI output: translation files include line numbers for extracted strings, and adding new code changed the line numbers. My preference is to include filenames but not line numbers in PO files (using |
@merwok thank you very much for the feedback! |
@VaZark thank you very much for the effort and the good PR! |
Thanks @fabiocaccamo ! Glad that this was my first-ever PR |
Related to : #199