Added a migration to correct Message fields containing strings that are repr() of list instances instead of comma-separated email addresses.

- Legacy-Id: 17349
This commit is contained in:
Henrik Levkowetz 2020-02-26 18:06:52 +00:00
parent fb740ff6bf
commit 0b3ac2ac0e

View file

@ -0,0 +1,43 @@
# Copyright The IETF Trust 2020, All Rights Reserved
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-21 14:27
from __future__ import absolute_import, print_function, unicode_literals
from tqdm import tqdm
from django.db import migrations
import debug # pyflakes:ignore
def forward(apps, schema_editor):
Message = apps.get_model('message', 'Message')
for m in tqdm(Message.objects.all()):
dirty = False
for fieldname in ['to', 'cc', 'bcc', ]:
f = getattr(m, fieldname)
if f.startswith("['") or f.startswith('[]') or f.startswith("[u'"):
l = eval(f)
if isinstance(l, list):
f = ','.join(l)
setattr(m, fieldname, f)
dirty = True
if dirty:
m.save()
def reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('message', '0008_set_message_sent'),
]
operations = [
migrations.RunPython(forward, reverse),
]