Skip to content

Commit 0b3ac2a

Browse files
committed
Added a migration to correct Message fields containing strings that are repr() of list instances instead of comma-separated email addresses.
- Legacy-Id: 17349
1 parent fb740ff commit 0b3ac2a

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
# Generated by Django 1.11.20 on 2019-05-21 14:27
4+
5+
6+
from __future__ import absolute_import, print_function, unicode_literals
7+
8+
from tqdm import tqdm
9+
10+
from django.db import migrations
11+
12+
import debug # pyflakes:ignore
13+
14+
15+
def forward(apps, schema_editor):
16+
17+
Message = apps.get_model('message', 'Message')
18+
19+
for m in tqdm(Message.objects.all()):
20+
dirty = False
21+
for fieldname in ['to', 'cc', 'bcc', ]:
22+
f = getattr(m, fieldname)
23+
if f.startswith("['") or f.startswith('[]') or f.startswith("[u'"):
24+
l = eval(f)
25+
if isinstance(l, list):
26+
f = ','.join(l)
27+
setattr(m, fieldname, f)
28+
dirty = True
29+
if dirty:
30+
m.save()
31+
32+
def reverse(apps, schema_editor):
33+
pass
34+
35+
class Migration(migrations.Migration):
36+
37+
dependencies = [
38+
('message', '0008_set_message_sent'),
39+
]
40+
41+
operations = [
42+
migrations.RunPython(forward, reverse),
43+
]

0 commit comments

Comments
 (0)