Skip to content

Call get_setting with setting.name#4000

Merged
ajrbyers merged 3 commits into
openlibhums:masterfrom
gamboz:patch-2
Mar 14, 2024
Merged

Call get_setting with setting.name#4000
ajrbyers merged 3 commits into
openlibhums:masterfrom
gamboz:patch-2

Conversation

@gamboz

@gamboz gamboz commented Mar 1, 2024

Copy link
Copy Markdown
Collaborator

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

@ajrbyers ajrbyers left a comment

Copy link
Copy Markdown
Member

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.

Comment thread src/utils/setting_handler.py Outdated
value is present
"""
if not isinstance(setting_name, str):
import inspect

Copy link
Copy Markdown
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
Copy Markdown
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

@joemull joemull left a comment

Copy link
Copy Markdown
Member

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

gamboz commented Mar 13, 2024

Copy link
Copy Markdown
Collaborator Author

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