From 00741998450b5894c0980332dbcfe7c08b162f48 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Sun, 14 Sep 2025 11:11:15 -0500 Subject: [PATCH] Update migration and arrange for activation changes --- .../migrations/0016_configrevision_active.py | 24 ++++++++++++++++++- netbox/core/models/config.py | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/netbox/core/migrations/0016_configrevision_active.py b/netbox/core/migrations/0016_configrevision_active.py index 1290728982..af04202ed4 100644 --- a/netbox/core/migrations/0016_configrevision_active.py +++ b/netbox/core/migrations/0016_configrevision_active.py @@ -3,6 +3,27 @@ from django.db import migrations, models +def get_active(apps, schema_editor): + from django.core.cache import cache + ConfigRevision = apps.get_model('core', 'ConfigRevision') + version = None + revision = None + + try: + version = cache.get('config_version') + except Exception: + pass + + if version: + revision = ConfigRevision.objects.filter(pk=version).first() + else: + revision = ConfigRevision.objects.order_by('-created').first() + + if revision: + revision.active = True + revision.save() + + class Migration(migrations.Migration): dependencies = [ @@ -15,10 +36,11 @@ class Migration(migrations.Migration): name='active', field=models.BooleanField(default=False), ), + migrations.RunPython(code=get_active, reverse_code=migrations.RunPython.noop), migrations.AddConstraint( model_name='configrevision', constraint=models.UniqueConstraint( - condition=models.Q(('actvive', True)), fields=('active',), name='unique_active_config_revision' + condition=models.Q(('active', True)), fields=('active',), name='unique_active_config_revision' ), ), ] diff --git a/netbox/core/models/config.py b/netbox/core/models/config.py index 6a0f922aa5..d97c6e53c5 100644 --- a/netbox/core/models/config.py +++ b/netbox/core/models/config.py @@ -41,7 +41,7 @@ class ConfigRevision(models.Model): constraints = [ models.UniqueConstraint( fields=('active',), - condition=models.Q(actvive=True), + condition=models.Q(active=True), name='unique_active_config_revision', ) ] @@ -78,4 +78,4 @@ class ConfigRevision(models.Model): @property def is_active(self): - return cache.get('config_version') == self.pk + return self.active