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: Create relationships between draft and rfc Documents #5890

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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