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.
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 distinctmodel_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
becausecanonical_uuid
is a property on theChange
model and causes a "No setter defined" error if we try to annotate it on the queryset. If we rundistinct
oncid
, we get the desired result, becausecid
will either equalmodel_instance_uuid
(if not NULL) oruuid
.