fix: prevent dups in DraftAliasGenerator (#7650)

This commit is contained in:
Jennifer Richards 2024-07-10 17:34:04 -03:00 committed by GitHub
parent 20f183c948
commit b2a858c880
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1389,15 +1389,17 @@ class DraftAliasGenerator:
# states__type_id, states__slug directly in the `filter()`
# works, but it does not work as expected in `exclude()`.
active_state = State.objects.get(type_id="draft", slug="active")
active_pks = [] # build a static list of the drafts we actually returned as "active"
active_drafts = drafts.filter(states=active_state)
for this_draft in active_drafts:
active_pks.append(this_draft.pk)
for alias, addresses in self._yield_aliases_for_draft(this_draft):
yield alias, addresses
# Annotate with the draft state slug so we can check for drafts that
# have become RFCs
inactive_recent_drafts = (
drafts.exclude(states=active_state)
drafts.exclude(pk__in=active_pks) # don't re-filter by state, states may have changed during the run!
.filter(expires__gte=show_since)
.annotate(
# Why _default_manager instead of objects? See: