-
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.
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.
app/dao/fact_billing_dao.py
Outdated
@@ -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( |
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.
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) |
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.
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( |
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.
And another one.
app/dao/services_dao.py
Outdated
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) |
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.
Here
app/dao/services_dao.py
Outdated
@@ -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)) |
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.
Here
app/dao/services_dao.py
Outdated
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])) |
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.
Here
app/dao/services_dao.py
Outdated
@@ -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) |
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.
Still here
app/dao/services_dao.py
Outdated
).label("permanent_failure_rate"), | ||
) | ||
.join(subquery, subquery.c.service_id == Notification.service_id) | ||
.join(substmt, substmt.c.service_id == Notification.service_id) | ||
.filter( |
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.
Still here
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