-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix more sqlalchemy #1417
base: main
Are you sure you want to change the base?
fix more sqlalchemy #1417
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.
Thank you, @terrazoon, this is quite a bit of work and I know the last big push on the query updates! 🎉
I am curious about the change of query
to querie
and if that was intentional or not, as it is confusing. After catching up in Slack about this, perhaps a quick note explaining the naming would be helpful, and/or a future cleanup task to update the names again/correct the spelling.
I'd also call out the use of scalars()
again with some of these, just to make sure that's the intended change we need to have on all of these queries and that it doesn't disrupt anything with the results we're getting back. It only bit us once so far, but noting it again to be absolutely sure!
With the adjustments to some of the tests to also account for the use of scalars()
, we're going to have to make sure that the results that the app itself is expecting are still accurate and correct, so there will be a lot of QA involved.
app/dao/fact_billing_dao.py
Outdated
@@ -65,7 +65,7 @@ def fetch_sms_free_allowance_remainder_until_date(end_date): | |||
|
|||
def fetch_sms_billing_for_all_services(start_date, end_date): | |||
# ASSUMPTION: AnnualBilling has been populated for year. | |||
allowance_left_at_start_date_query = fetch_sms_free_allowance_remainder_until_date( | |||
allowance_left_at_start_date_querie = fetch_sms_free_allowance_remainder_until_date( |
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.
Was this supposed to be changed to allowance_left_at_start_date_queries
?
allowance_left_at_start_date_querie = fetch_sms_free_allowance_remainder_until_date( | |
allowance_left_at_start_date_queries = fetch_sms_free_allowance_remainder_until_date( |
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.
I've changed all the querie to stmt, with the side effect that you will now see sub stmt in places.
app/dao/fact_billing_dao.py
Outdated
@@ -76,14 +76,14 @@ def fetch_sms_billing_for_all_services(start_date, end_date): | |||
# subtract sms_billable_units units accrued since report's start date to get up-to-date | |||
# allowance remainder | |||
sms_allowance_left = func.greatest( | |||
allowance_left_at_start_date_query.c.sms_remainder - sms_billable_units, 0 | |||
allowance_left_at_start_date_querie.c.sms_remainder - sms_billable_units, 0 |
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.
Same question on the name change:
allowance_left_at_start_date_querie.c.sms_remainder - sms_billable_units, 0 | |
allowance_left_at_start_date_queries.c.sms_remainder - sms_billable_units, 0 |
app/dao/fact_billing_dao.py
Outdated
) | ||
|
||
# billable units here are for period between start date and end date only, so to see | ||
# how many are chargeable, we need to see how much free allowance was used up in the | ||
# period up until report's start date and then do a subtraction | ||
chargeable_sms = func.greatest( | ||
sms_billable_units - allowance_left_at_start_date_query.c.sms_remainder, 0 | ||
sms_billable_units - allowance_left_at_start_date_querie.c.sms_remainder, 0 |
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.
Same question on the name change:
sms_billable_units - allowance_left_at_start_date_querie.c.sms_remainder, 0 | |
sms_billable_units - allowance_left_at_start_date_queries.c.sms_remainder, 0 |
app/dao/fact_billing_dao.py
Outdated
@@ -93,7 +93,7 @@ def fetch_sms_billing_for_all_services(start_date, end_date): | |||
Organization.id.label("organization_id"), | |||
Service.name.label("service_name"), | |||
Service.id.label("service_id"), | |||
allowance_left_at_start_date_query.c.free_sms_fragment_limit, | |||
allowance_left_at_start_date_querie.c.free_sms_fragment_limit, |
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.
Same question on the name change:
allowance_left_at_start_date_querie.c.free_sms_fragment_limit, | |
allowance_left_at_start_date_queries.c.free_sms_fragment_limit, |
app/dao/fact_billing_dao.py
Outdated
allowance_left_at_start_date_querie, | ||
Service.id == allowance_left_at_start_date_querie.c.service_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.
Same question on the name change:
allowance_left_at_start_date_querie, | |
Service.id == allowance_left_at_start_date_querie.c.service_id, | |
allowance_left_at_start_date_queries, | |
Service.id == allowance_left_at_start_date_queries.c.service_id, |
app/dao/fact_billing_dao.py
Outdated
allowance_left_at_start_date_querie.c.free_sms_fragment_limit, | ||
allowance_left_at_start_date_querie.c.sms_remainder, |
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.
Same question on the name change:
allowance_left_at_start_date_querie.c.free_sms_fragment_limit, | |
allowance_left_at_start_date_querie.c.sms_remainder, | |
allowance_left_at_start_date_queries.c.free_sms_fragment_limit, | |
allowance_left_at_start_date_queries.c.sms_remainder, |
app/performance_dashboard/rest.py
Outdated
@@ -100,6 +100,7 @@ def transform_into_notification_by_type_json(total_notifications): | |||
def transform_processing_time_results_to_json(processing_time_results): | |||
j = [] | |||
for x in processing_time_results: | |||
print(f"HERE IS A PROCESSING TIME RESULT {x}") |
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.
Do we need to keep this print
statement? If so, is there a more useful logging statement we could use instead?
If not, then let's remove!
print(f"HERE IS A PROCESSING TIME RESULT {x}") |
@@ -77,7 +79,7 @@ def test_get_processing_time_percentage_for_date_range_handles_zero_cases( | |||
) | |||
|
|||
results = get_processing_time_percentage_for_date_range("2021-02-21", "2021-02-22") | |||
|
|||
print(f"HERE ARE THE RESULTS {results}") |
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.
Same, do we need this print
statement here in the tests?
print(f"HERE ARE THE RESULTS {results}") |
Description
Fix remaining queries affected by the upgrade to sqlalchemy 2.0
NOTE: To find things that need changing the search is
grep -ri "query\." ./**/**.py
. In order to make search either, occurrences where 'query' was just being used as a variable name were changed to 'querie'.NOTE: There is one test in notification_dao where I changed the expected result. I think sqlalchemy broke whatever strange thing that test was trying to do. As a matter of good maintenance, I don't think the test is doing the right thing trying to override the behavior of the Pagination object based on a flag.
Security Considerations
N/A