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 100 commits into
base: main
Choose a base branch
from
Open

fix more sqlalchemy #1417

wants to merge 100 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
Copy link
Contributor

@xlorepdarkhelm xlorepdarkhelm left a comment

Choose a reason for hiding this comment

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

More filter() and filter_by() found. I actually went through and identified all the places I saw it in the code this time.

Might be good to search through the codebase for .filter( and .filter_by( to find the remaining ones.

@@ -622,7 +622,7 @@ def fetch_sms_billing_for_organization(organization_id, financial_year):
AnnualBilling.financial_year_start == financial_year,
),
)
.outerjoin(ft_billing_subquery, Service.id == ft_billing_subquery.c.service_id)
.outerjoin(ft_billing_substmt, Service.id == ft_billing_substmt.c.service_id)
.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

Found another one.

@@ -377,19 +377,19 @@ def fetch_stats_for_all_services_by_date_range(
)
)
if not include_from_test_key:
subquery = subquery.filter(Notification.key_type != KeyType.TEST)
subquery = subquery.subquery()
substmt = substmt.filter(Notification.key_type != KeyType.TEST)
Copy link
Contributor

Choose a reason for hiding this comment

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

And another one

@@ -546,11 +546,11 @@ def get_total_notifications_for_date_range(start_date, end_date):
.order_by(FactNotificationStatus.local_date)
)
if start_date and end_date:
query = query.filter(
stmt = stmt.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

And another one.

select(Service).filter_by(id=service_id).options(joinedload(Service.api_keys))
select(Service)
.where(Service.id == service_id)
.options(joinedload(Service.api_keys))
)
if only_active:
stmt = stmt.filter(Service.active)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here

@@ -392,24 +394,36 @@ def _delete_commit(stmt):
db.session.execute(stmt)
db.session.commit()

subq = select(Template.id).filter_by(service=service).subquery()
subq = select(Template.id).where(Template.service == service).subquery()

stmt = delete(TemplateRedacted).filter(TemplateRedacted.template_id.in_(subq))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here

ApiKey.get_history_model().service_id == service.id
)
)
_delete_commit(delete(AnnualBilling).where(AnnualBilling.service_id == service.id))

stmt = (
select(VerifyCode).join(User).filter(User.id.in_([x.id for x in service.users]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Here

@@ -530,9 +530,9 @@ def dao_fetch_todays_stats_for_all_services(
)

if not include_from_test_key:
subquery = subquery.filter(Notification.key_type != KeyType.TEST)
substmt = substmt.filter(Notification.key_type != KeyType.TEST)
Copy link
Contributor

Choose a reason for hiding this comment

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

Still here

).label("permanent_failure_rate"),
)
.join(subquery, subquery.c.service_id == Notification.service_id)
.join(substmt, substmt.c.service_id == Notification.service_id)
.filter(
Copy link
Contributor

Choose a reason for hiding this comment

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

Still here

@terrazoon terrazoon requested a review from a team December 26, 2024 19:52
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