Fix edge case in func test data purging for created_by_id

When running the purge command I found about 4 users who could not be
deleted because their user id was still referenced in the services table
as they had created the service yet they were not a member of that
service anymore.

I have fixed this by checking that if they are not a member but created
the service then we also delete the service for them.

Note, I've followed the previous convention of no tests for this
function. I've run it locally and executed the code path so there should
be no major flaws in the code. There is a small chance I wasn't able to
exactly replicate the state that existed in preview on my local but
hopefully it was close enough to be accurate.
This commit is contained in:
David McDonald
2020-05-18 10:30:28 +01:00
parent df5ccae4c5
commit 2f0b3a9636
2 changed files with 22 additions and 2 deletions

View File

@@ -234,6 +234,16 @@ def dao_fetch_all_services_by_user(user_id, only_active=False):
return query.all()
def dao_fetch_all_services_created_by_user(user_id):
query = Service.query.filter_by(
created_by_id=user_id
).order_by(
asc(Service.created_at)
)
return query.all()
@transactional
@version_class(
VersionOptions(ApiKey, must_write_history=False),