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

Call get_setting with setting.name #4000

Merged
merged 3 commits into from
Mar 14, 2024
Merged

Conversation

gamboz
Copy link
Collaborator

@gamboz gamboz commented Mar 1, 2024

Sometimes the function utils.settings_handler.get_setting() is called with a wrong argument.

The function expects a string as second argument (setting_name), but here and there it is called with a core.Setting object instead. I think that everything works fine anyway because str(Setting) is Setting.name, but I thought I should mention 🙂

Here I fix a couple of calls, and I add (temporary) code to report if someone is calling with non-str argument.

and report if someone is calling with non-str argument
Copy link
Member

@ajrbyers ajrbyers left a comment

Choose a reason for hiding this comment

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

Thanks @gamboz, one comment in the review.

@@ -91,6 +91,13 @@ def get_setting(
:default: If True, returns the default SettingValue when no journal specific
value is present
"""
if not isinstance(setting_name, str):
import inspect
Copy link
Member

Choose a reason for hiding this comment

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

Can the import statement be shifted to the header?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved.

I wasn't sure if you wanted to keep this sort of workaround, so I kept everything close for easier deletion 🙂

@joemull joemull requested a review from ajrbyers March 13, 2024 15:01
Copy link
Member

@joemull joemull left a comment

Choose a reason for hiding this comment

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

Thanks gamboz--it is helpful to have the warning for sure. We can remove it when / if we put in Python type annotations, or if we add unit tests to the functions that call get_setting, with assertions like Mock.assertCalledWith.

If we want to make it clear it is temporary, maybe we could add a comment about that fact?

@gamboz
Copy link
Collaborator Author

gamboz commented Mar 13, 2024

Thanks gamboz--it is helpful to have the warning for sure. We can remove it when / if we put in Python type annotations, or if we add unit tests to the functions that call get_setting, with assertions like Mock.assertCalledWith.

If we want to make it clear it is temporary, maybe we could add a comment about that fact?

done

@ajrbyers ajrbyers merged commit bcc9032 into openlibhums:master Mar 14, 2024
1 check failed
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