NASA-IMPACT / admg-backend

Apache License 2.0
2 stars 0 forks source link

Bugfix/multiple unpublished dependents #609

Closed edkeeble closed 7 months ago

edkeeble commented 7 months ago

Resolves #600 #608

In Postgresql, DISTINCT treats NULL values as equal (ref: https://www.postgresql.org/docs/12/queries-select-lists.html). Since unpublished objects have no model_instance_uuid, our attempt to filter dependent objects by distinct model_instance_uuids had the unintended side effect of preventing us from displaying multiple unpublished objects.

I've resolved this by annotating the queryset with a canonical uuid field (named cid because canonical_uuid is a property on the Change model and causes a "No setter defined" error if we try to annotate it on the queryset. If we run distinct on cid, we get the desired result, because cid will either equal model_instance_uuid (if not NULL) or uuid.