Skip to content

Commit e289d7a

Browse files
pandafynemesifier
authored andcommitted
[fix] Populate Config.checksum_db field without modifying Config.status #1113
Bug: Config.update_status_if_checksum_changed() sets the Config.status to modified if the Config.checksum_db field is empty. In the migration Config.checksum_db is empty, thus all Config.status is set to modified to all devices. Fix: Use Config.objects.bulk_update() to populate the Config.checksum_db field. It does not call save(), nor it sends pre_save and post_save signals. Thus, it avoids any side-effects from the migration. [skip changelog] Related to #1113
1 parent ac6fd83 commit e289d7a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

openwisp_controller/config/migrations/0061_config_checksum_db.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,29 @@ def populate_checksum_db(apps, schema_editor):
88
"""
99
Populate checksum_db field with current checksum values
1010
for existing Config objects.
11+
12+
We don't want to change the Config.status when populating this field,
13+
hence we use Config.objects.bulk_update() instead of
14+
Config.update_status_if_checksum_changed().
1115
"""
1216
Config = load_model("config", "Config")
17+
chunk_size = 100
18+
updated_configs = []
1319
qs = (
1420
Config.objects.prefetch_related("vpnclient_set", "templates")
1521
.select_related("device", "device__organization__config_settings")
1622
.filter(checksum_db__isnull=True)
17-
.iterator(chunk_size=100)
23+
.iterator(chunk_size=chunk_size)
1824
)
1925
for config in qs:
20-
config.update_status_if_checksum_changed()
26+
config.checksum_db = config.checksum
27+
updated_configs.append(config)
28+
if len(updated_configs) >= chunk_size:
29+
Config.objects.bulk_update(updated_configs, ["checksum_db"])
30+
updated_configs = []
31+
32+
if updated_configs:
33+
Config.objects.bulk_update(updated_configs, ["checksum_db"])
2134

2235

2336
class Migration(migrations.Migration):

0 commit comments

Comments
 (0)