Skip to content

Commit 355c5cb

Browse files
committed
Updated doc migration 0029 to avoid duplicate actions, and to avoid database referential inconsistency due to case differences in email addresses.
- Legacy-Id: 13370
1 parent fe30afd commit 355c5cb

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

ietf/doc/migrations/0029_update_rfc_authors.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,15 +1320,18 @@ def plain_name(person):
13201320

13211321
def forward(apps, schema_editor):
13221322
Document = apps.get_model('doc','Document')
1323+
Email = apps.get_model('person', 'Email')
13231324
EditedAuthorsDocEvent = apps.get_model('doc','EditedAuthorsDocEvent')
13241325
today = datetime.date.today().isoformat()
1326+
print("") # don't let tqdm overwrite the migration name
13251327
for rfc_num, addlist, removelist in tqdm(changes):
13261328
rfc = Document.objects.get(docalias__name='rfc%d'%rfc_num)
1327-
old_authors = ", ".join([plain_name(a.person) for a in rfc.authors.all()])
1329+
old_authors = ", ".join([plain_name(a.person) for a in rfc.authors.distinct()])
13281330
rfc.documentauthor_set.filter(author__person_id__in=removelist).delete()
13291331
for addr in addlist:
1330-
rfc.documentauthor_set.create(author_id=addr,order = -1)
1331-
new_authors = ", ".join([plain_name(a.person) for a in rfc.authors.all()])
1332+
email = Email.objects.get(address__iexact=addr)
1333+
rfc.documentauthor_set.create(author_id=email.address, order = -1)
1334+
new_authors = ", ".join([plain_name(a.person) for a in rfc.authors.distinct()])
13321335
EditedAuthorsDocEvent.objects.create(
13331336
by_id=1, # (System)
13341337
type='edited_authors',
@@ -1340,7 +1343,7 @@ def forward(apps, schema_editor):
13401343

13411344
def reverse(apps, schema_editor):
13421345
Document = apps.get_model('doc','Document')
1343-
Document.objects.get(docalias__name='rfc1070').documentauthor_set.all().delete()
1346+
Document.objects.get(docalias__name='rfc1070').documentauthor_set.distinct().delete()
13441347
pass
13451348

13461349
class Migration(migrations.Migration):

0 commit comments

Comments
 (0)