The update of SQLAlchemy 1.4.10 has caused some conflicts in our code. This PR fixes most of those conflicts.

- sqlalchemy.sql.expression.case must include an else statement.
- clearly define list of columns for inbound_sms_history insert, getting the list from InboundSmsHistory.__table__.c was causing data type errors.
- remove relationships when not needed, the foreign key relationship is established in the creation of the column. This will get rid of the warnings referenced here: http://sqlalche.me/e/14/qzyx.
- update queries now that he user relationship in ServiceUser db model has been removed.
- move the check that a template is archived to the view instead of the dao method. The check was clearing the session before the version history could be done.

Deleting notifications in the night tasks still needs to be
investigated. The raw sql is causing an error.
This commit is contained in:
Rebecca Law
2021-04-26 11:50:17 +01:00
parent df19a91b7f
commit 68d28aa83b
8 changed files with 24 additions and 50 deletions

View File

@@ -150,9 +150,12 @@ def fetch_letter_line_items_for_all_services(start_date, end_date):
[(FactBilling.postage.in_(INTERNATIONAL_POSTAGE_TYPES), "international")], else_=FactBilling.postage
).label("postage")
postage_order = case(((formatted_postage == "second", 1),
(formatted_postage == "first", 2),
(formatted_postage == "international", 3)))
postage_order = case(
(formatted_postage == "second", 1),
(formatted_postage == "first", 2),
(formatted_postage == "international", 3),
else_=0 # assumes never get 0 as a result
)
query = db.session.query(
Organisation.name.label("organisation_name"),

View File

@@ -71,7 +71,13 @@ def dao_count_inbound_sms_for_service(service_id, limit_days):
def _insert_inbound_sms_history(subquery, query_limit=10000):
offset = 0
inbound_sms_query = db.session.query(
*[x.name for x in InboundSmsHistory.__table__.c]
InboundSms.id,
InboundSms.created_at,
InboundSms.service_id,
InboundSms.notify_number,
InboundSms.provider_date,
InboundSms.provider_reference,
InboundSms.provider
).filter(InboundSms.id.in_(subquery))
inbound_sms_count = inbound_sms_query.count()

View File

@@ -9,9 +9,13 @@ def dao_get_service_user(user_id, service_id):
def dao_get_active_service_users(service_id):
query = ServiceUser.query.join(ServiceUser.user).filter(
ServiceUser.service_id == service_id,
User.state == 'active'
query = db.session.query(
ServiceUser
).join(
User, User.id == ServiceUser.user_id
).filter(
User.state == 'active',
ServiceUser.service_id == service_id
)
return query.all()

View File

@@ -43,9 +43,6 @@ def dao_create_template(template):
VersionOptions(Template, history_class=TemplateHistory)
)
def dao_update_template(template):
if template.archived:
template.folder = None
db.session.add(template)