-
Notifications
You must be signed in to change notification settings - Fork 29
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
Switch @validate_country to decorator #1970
Conversation
f4ea3f7
to
e277100
Compare
@@ -50,9 +51,6 @@ def get_economic_impact( | |||
dict: The economic impact. | |||
""" | |||
print(f"Got request for {country_id} {policy_id} {baseline_policy_id}") |
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.
With this change, this line will no longer print for invalid countries. Is it important to preserve this behavior (ie: we want to print all requested countries)? If so, perhaps it's best to add this printing/logging elsewhere. Otherwise, perhaps it can be removed entirely?
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.
No, I don't think it's important to maintain this logging. Removing is totally fine.
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.
It looks like this function moved to policyengine_api/routes/economy_routes.py
. I've made the update there and removed his comment.
Thank you for this work @ldorner. I will review probably tomorrow, depending on progress on some things I need to catch up on from some time off. |
b897af6
to
6030263
Compare
I rebased to pull in recent changes/resolve conflicts. |
@ldorner Unfortunately, it looks like the added test still fails due to accessing the |
Sorry! Bad merge. Fixed now :) |
@ldorner Thanks again for this, will review early tomorrow |
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.
@ldorner This is perfect! Thank you very much, this removes so many instances of us importing and running the old function.
Overview
Currently, there is a repeated check and short-circuit in many functions to validate existence of the given country ID. This PR refactors
validate_country
as a decorator to DRY the code. We may consider transitioning this to abefore_request
hook to further reduce code repetition.This is essentially a refactor. There should be no functional change.
Changes
validate_country
to change it into a decorator/wrappervalidate_country()
check & short circuit ->@validate_country
decoratorvalidate_country
functiontest_policy.py
to ensure that the decorator functionality works