Skip to content

Commit 456c201

Browse files
Update openwisp_controller/config/migrations/0056_ow_zt_to_global.py
Fix issue so that it saves updated templates Co-authored-by: Gagan Deep <[email protected]>
1 parent 22a0382 commit 456c201

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

openwisp_controller/config/migrations/0056_ow_zt_to_global.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
from django.db import migrations
2-
import json
2+
from django.db import migrations
33

44

55
def change_owzt_to_global(apps, schema_editor):
66
Template = apps.get_model('config', 'Template')
7+
updated_templates = set()
78
for template in Template.objects.filter(
8-
type='vpn', vpn__backend='openwisp_controller.vpn_backends.ZeroTier'):
9-
config = json.loads(template.config)
10-
if 'zerotier' in config:
11-
for item in config.get('zerotier', []):
9+
type='vpn', vpn__backend='openwisp_controller.vpn_backends.ZeroTier'
10+
):
11+
if 'zerotier' in template.config:
12+
for item in template.config.get('zerotier', []):
1213
if item.get('name') == 'ow_zt':
1314
item['name'] = 'global'
15+
updated_templates.add(template)
16+
Template.objects.bulk_update(updated_templates, ['config'])
1417

1518

1619
class Migration(migrations.Migration):

0 commit comments

Comments
 (0)