Skip to content

Commit

Permalink
fix: Create relationships between draft and rfc Documents (#5890)
Browse files Browse the repository at this point in the history
* fix: Create RelatedDocument between draft and rfc Documents

* chore: Improve comment

* refactor: Clarify migration
  • Loading branch information
jennifer-richards authored Jun 28, 2023
1 parent 877bc02 commit bff145f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ietf/doc/migrations/0007_create_rfc_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def forward(apps, schema_editor):
assert set(found_by_name) == set(found_by_state), "mismatch between rfcs identified by state and docalias"

# As of 2023-06-15, there is one Document with two rfc aliases: rfc6312 and rfc6342 are the same Document. This
# was due to a publication error. We'll handle that specially.
# was due to a publication error. Because we go alias-by-alias, no special handling is needed in this migration.

for rfc_alias in rfc_docaliases.order_by("name"):
assert rfc_alias.docs.count() == 1, f"DocAlias {rfc_alias} is linked to more than 1 Document"
Expand Down
20 changes: 18 additions & 2 deletions ietf/doc/migrations/0009_move_rfc_docaliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@


def forward(apps, schema_editor):
"""Point "rfc..." DocAliases at the rfc-type Document"""
"""Point "rfc..." DocAliases at the rfc-type Document
Creates a became-rfc RelatedDocument to preserve the connection between the draft and the rfc.
"""
DocAlias = apps.get_model("doc", "DocAlias")
Document = apps.get_model("doc", "Document")
RelatedDocument = apps.get_model("doc", "RelatedDocument")

for rfc_alias in DocAlias.objects.filter(name__startswith="rfc"):
rfc = Document.objects.get(name=rfc_alias.name)
rfc_alias.docs.set([rfc])
aliased_doc = rfc_alias.docs.get() # implicitly confirms only one value in rfc_alias.docs
if aliased_doc != rfc:
# If the DocAlias was not already pointing at the rfc, it was pointing at the draft
# it came from. Create the relationship between draft and rfc Documents.
assert aliased_doc.type_id == "draft", f"Alias for {rfc.name} should be pointing at a draft"
RelatedDocument.objects.create(
source=aliased_doc,
target=rfc_alias,
relationship_id="became-rfc",
)
# Now move the alias from the draft to the rfc
rfc_alias.docs.set([rfc])


class Migration(migrations.Migration):
Expand Down

0 comments on commit bff145f

Please sign in to comment.