Skip to content

Commit 13c3ce3

Browse files
committed
Don't populate ObjectTypes during migration
1 parent 533fe55 commit 13c3ce3

File tree

3 files changed

+2
-28
lines changed

3 files changed

+2
-28
lines changed

netbox/core/migrations/0017_concrete_objecttype.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@
33
from django.db import migrations, models
44

55

6-
def populate_object_types(apps, schema_editor):
7-
"""
8-
Create an ObjectType record for each valid ContentType.
9-
"""
10-
ContentType = apps.get_model('contenttypes', 'ContentType')
11-
ObjectType = apps.get_model('core', 'ObjectType')
12-
13-
for ct in ContentType.objects.all():
14-
try:
15-
# Validate ContentType
16-
apps.get_model(ct.app_label, ct.model)
17-
except LookupError:
18-
continue
19-
# TODO assign public/features
20-
ObjectType(pk=ct.pk, features=[]).save_base(raw=True)
21-
22-
236
class Migration(migrations.Migration):
247

258
dependencies = [
@@ -69,9 +52,4 @@ class Migration(migrations.Migration):
6952
bases=('contenttypes.contenttype',),
7053
managers=[],
7154
),
72-
# Create an ObjectType record for each ContentType
73-
migrations.RunPython(
74-
code=populate_object_types,
75-
reverse_code=migrations.RunPython.noop,
76-
),
7755
]

netbox/core/models/contenttypes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def create(self, **kwargs):
2222
if (app_label := kwargs.get('app_label')) and (model := kwargs.get('model')):
2323
try:
2424
kwargs['contenttype_ptr'] = ContentType.objects.get(app_label=app_label, model=model)
25-
kwargs.pop('app_label')
26-
kwargs.pop('model')
2725
except ObjectDoesNotExist:
2826
pass
2927
return super().create(**kwargs)

netbox/core/signals.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,14 @@ def update_object_types(sender, **kwargs):
6262
ot = ObjectType.objects.get_by_natural_key(app_label=app_label, model=model_name)
6363
ot.public = is_public
6464
ot.features = features
65+
ot.save()
6566
except ObjectDoesNotExist:
66-
ct = ContentType.objects.get_for_model(model)
67-
ot = ObjectType(
68-
contenttype_ptr=ct,
67+
ObjectType.objects.create(
6968
app_label=app_label,
7069
model=model_name,
7170
public=is_public,
7271
features=features,
7372
)
74-
ot.save()
7573

7674

7775
@receiver(post_save, sender=ContentType)

0 commit comments

Comments
 (0)