-
-
Notifications
You must be signed in to change notification settings - Fork 186
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(trashBin): ensure the project is fully restored from the admin interface TASK-1645 #5563
base: release/2.024.36
Are you sure you want to change the base?
Conversation
asset = Asset.all_objects.only( | ||
'pk', 'name', 'uid', 'owner_id' | ||
).get(uid=self.kpi_asset_uid) | ||
except Asset.DoesNotExist: | ||
try: | ||
asset = Asset.objects.only('pk').get( | ||
_deployment_data__formid=self.pk | ||
) | ||
asset = Asset.all_objects.only( | ||
'pk', 'name', 'uid', 'owner_id' | ||
).get(_deployment_data__formid=self.pk) | ||
except Asset.DoesNotExist: | ||
# An `Asset` object needs to be returned to avoid 500 while | ||
# Enketo is fetching for project XML (e.g: /formList, /manifest) | ||
asset = Asset(uid=self.id_string) | ||
asset = Asset( | ||
uid=self.id_string, | ||
name=self.title, | ||
owner_id=self.user.id, | ||
) |
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.
Part of #5514 , add new fields to avoids conflicts with release/2.025.02
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.
2 small things
@@ -126,16 +126,22 @@ def asset(self): | |||
# uses an Asset object only to narrow down a query with a 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.
This comment is no longer accurate
) | ||
asset = Asset.all_objects.only( | ||
'pk', 'name', 'uid', 'owner_id' | ||
).get(_deployment_data__formid=self.pk) |
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.
I don't think using only
helps us any here if we have to call get
on a different field anyway
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.
It does ;-)
In [1]: Asset.objects.only('pk', 'uid', 'name').get(_deployment_data__backend_response__formid=428)
SELECT "kpi_asset"."id",
"kpi_asset"."name",
"kpi_asset"."uid"
FROM "kpi_asset"
WHERE (NOT ("kpi_asset"."pending_delete") AND ("kpi_asset"."_deployment_data" #> '{backend_response,formid}') = '428'::jsonb)
LIMIT 21
Execution time: 0.013126s [Database: default]
Out[1]: <Asset: Project with audio (as2gssYmeivHnk5f7zXPbY)>
Having that said, you made see there was a problem with the condition ;-)
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.
Huh. Django is smarter than I gave it credit
📣 Summary
Fixed an issue where projects were not being completely restored from the trash.
📖 Description
A bug prevented projects from being fully restored after being moved to the trash, leading to missing or incomplete data upon recovery.
💭 Notes
Some unittests were apparently missing for this part, this PR adds two new tests. Moreover, part of kpi#5514 has been backported to this release.
👀 Preview steps
Bug template:
This snippet should raise an exception
This snippet shouldn't raise an exception