Skip to content

Commit 5e392b9

Browse files
pandafynemesifier
authored andcommitted
[fix] Use "iterator" method instead of "all" to iterate over objects
Updated code in data migrations which used "Model.objects.all()" to use "Model.objects.all()".
1 parent d1c1b81 commit 5e392b9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

openwisp_monitoring/check/migrations/0007_create_checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def create_ping_checks(apps, schema_editor):
1010
ContentType = apps.get_model('contenttypes', 'ContentType')
1111
Check = apps.get_model('check', 'Check')
1212
Device = apps.get_model('config', 'Device')
13-
for device in Device.objects.all():
13+
for device in Device.objects.iterator():
1414
auto_create_check(
1515
model=Device.__name__.lower(),
1616
app_label=Device._meta.app_label,
@@ -28,7 +28,7 @@ def create_config_applied_checks(apps, schema_editor):
2828
ContentType = apps.get_model('contenttypes', 'ContentType')
2929
Check = apps.get_model('check', 'Check')
3030
Device = apps.get_model('config', 'Device')
31-
for device in Device.objects.all():
31+
for device in Device.objects.iterator():
3232
auto_create_check(
3333
model=Device.__name__.lower(),
3434
app_label=Device._meta.app_label,

openwisp_monitoring/device/migrations/0001_squashed_0002_devicemonitoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def create_device_monitoring(apps, schema_editor):
1818
"""Data migration"""
1919
Device = apps.get_model('config', 'Device')
2020
DeviceMonitoring = apps.get_model('device_monitoring', 'DeviceMonitoring')
21-
for device in Device.objects.all():
21+
for device in Device.objects.iterator():
2222
DeviceMonitoring.objects.create(device=device)
2323

2424

0 commit comments

Comments
 (0)