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: Duplicate projects in query #949

Merged
merged 4 commits into from
Nov 2, 2023

Conversation

david-code
Copy link
Contributor

@david-code david-code commented Nov 2, 2023

Description

Caused by #870

When memberships are deleted, they are still included in the Django automatic joins between projects, membership lists and memberships. For example, here is the SQL generated by trying to select for related memberships from a project (made some manual edits for clarity when debugging):

SELECT p.name, ml.deleted_at AS ml_deleted, m.deleted_at AS m_deleted FROM "project_management_project" AS p
INNER JOIN "collaboration_membershiplist" AS ml
ON (p."membership_list_id" = ml."id")
INNER JOIN "collaboration_membership" AS m
ON (ml."id" = m."membership_list_id")
WHERE (m."user_id" = 'be080997-4edc-49cd-8f47-c69d2a3749e2'
AND p."deleted_at"
IS NULL) ORDER BY p."created_at" ASC;

You can see only projects are being checked if deleted_at IS NULL, when memberships and membership lists should be checked as well.

The easiest fix for now is just to add this check explicitly, like I've done. Eventually we need to figure out why this is not behaving as I expect.

David Code Howard and others added 3 commits November 2, 2023 15:26
* fix: add missing sitenote migration

* fix: linting

* fix: add copyright

* Update terraso_backend/apps/project_management/migrations/0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more.py

---------

Co-authored-by: Paul Schreiber <[email protected]>
@david-code david-code force-pushed the fix/duplicate-projects-in-query branch from ab2f9b1 to d0b9754 Compare November 2, 2023 19:29
@paulschreiber paulschreiber merged commit 2ffcc08 into main Nov 2, 2023
6 checks passed
@paulschreiber paulschreiber deleted the fix/duplicate-projects-in-query branch November 2, 2023 20:17
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