Skip to content

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

Merged
merged 16 commits into from
Nov 18, 2022
Merged

Respect 'using' in signals #200

merged 16 commits into from
Nov 18, 2022

Conversation

VaZark
Copy link
Contributor

@VaZark VaZark commented Nov 16, 2022

Related to : #199

Copy link
Owner

@fabiocaccamo fabiocaccamo left a 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?

theme_1 = Theme.objects.create(name="Custom 1", active=True)
kwargs = {"db" : "default"}
Theme.get_active_theme(**kwargs)

Copy link
Owner

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?

Copy link
Contributor Author

@VaZark VaZark Nov 17, 2022

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

Copy link
Owner

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@fabiocaccamo
Copy link
Owner

@merwok the CI lint step fails unexpectedly while checking the translations, do you know why / could you fix it?

@VaZark
Copy link
Contributor Author

VaZark commented Nov 17, 2022

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

theme_1 = Theme.objects.create(name="Custom 1", active=True)
kwargs = {"db" : "default"}
Theme.get_active_theme(**kwargs)

Copy link
Owner

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!

@fabiocaccamo
Copy link
Owner

@VaZark please update this branch from master, I have updated the test workflow for running tests even if the lint step fails.

Theme.get_active_theme()
objs_manager = Theme.objects
if "using" in kwargs:
objs_manager = objs_manager.using(kwargs["using"])
Copy link
Owner

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)

Copy link
Contributor Author

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.

@@ -42,8 +46,10 @@ def pre_save_handler(instance, **kwargs):
pass

@staticmethod
def get_active_theme():
def get_active_theme(*args, **kwargs):
Copy link
Owner

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".

Copy link
Contributor Author

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

@fabiocaccamo
Copy link
Owner

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

No, I don't understand the cause, for this reason I updated the test workflow.
If the PR passed all tests except the lint step I will merge it anyway.

@codecov
Copy link

codecov bot commented Nov 18, 2022

Codecov Report

Base: 95.55% // Head: 95.58% // Increases project coverage by +0.03% 🎉

Coverage data is based on head (cc8ba71) compared to base (7c9340b).
Patch coverage: 100.00% of modified lines in pull request are covered.

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              
Flag Coverage Δ
unittests 95.58% <100.00%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
admin_interface/models.py 100.00% <100.00%> (ø)

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@fabiocaccamo
Copy link
Owner

@VaZark tests are broken with postgres.

@VaZark
Copy link
Contributor Author

VaZark commented Nov 18, 2022

The pg tests were broken due to HOST and port not being set for github_workflow. It should be good now


@classmethod
def setUpTestData(cls):
Theme.objects.using("default").create(name="Change Active", active=True)
Copy link
Owner

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.

@fabiocaccamo fabiocaccamo merged commit 946b9c9 into fabiocaccamo:master Nov 18, 2022
@VaZark VaZark deleted the respect-signal-db branch November 18, 2022 12:13
@merwok
Copy link
Contributor

merwok commented Nov 18, 2022

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 makemessages --add-location=file).

@fabiocaccamo
Copy link
Owner

@merwok thank you very much for the feedback!

@fabiocaccamo
Copy link
Owner

@VaZark thank you very much for the effort and the good PR!

@VaZark
Copy link
Contributor Author

VaZark commented Nov 18, 2022

Thanks @fabiocaccamo ! Glad that this was my first-ever PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants