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

fix more sqlalchemy #1417

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open

fix more sqlalchemy #1417

wants to merge 78 commits into from

Conversation

terrazoon
Copy link
Contributor

@terrazoon terrazoon commented Nov 14, 2024

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

@terrazoon terrazoon marked this pull request as draft November 15, 2024 15:26
@terrazoon terrazoon marked this pull request as ready for review November 20, 2024 15:17
Copy link
Contributor

@ccostino ccostino left a 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.

@@ -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(
Copy link
Contributor

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?

Suggested change
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(

Copy link
Contributor Author

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.

@@ -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
Copy link
Contributor

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:

Suggested 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

)

# 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
Copy link
Contributor

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:

Suggested 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

@@ -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,
Copy link
Contributor

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:

Suggested change
allowance_left_at_start_date_querie.c.free_sms_fragment_limit,
allowance_left_at_start_date_queries.c.free_sms_fragment_limit,

Comment on lines 105 to 106
allowance_left_at_start_date_querie,
Service.id == allowance_left_at_start_date_querie.c.service_id,
Copy link
Contributor

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:

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

Comment on lines 123 to 124
allowance_left_at_start_date_querie.c.free_sms_fragment_limit,
allowance_left_at_start_date_querie.c.sms_remainder,
Copy link
Contributor

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:

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

@@ -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}")
Copy link
Contributor

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!

Suggested change
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}")
Copy link
Contributor

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?

Suggested change
print(f"HERE ARE THE RESULTS {results}")

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