Fix fresh-install migrations on PostgreSQL
Reading the runtime settings while other migrations run failed because the settings table did not exist yet. The error was caught, but it aborted the surrounding migration transaction on PostgreSQL. Run the query inside a savepoint. Verified with NetBox 4.7.2. Bump version to 0.14.3. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
cbb8128385
commit
1ed16c542a
3 files changed
+11
-8
No files matched your search
@@ -1,6 +1,6 @@
|
||||
from netbox.plugins import PluginConfig, get_plugin_config
|
||||
|
||||
__version__ = "0.14.2"
|
||||
__version__ = "0.14.3"
|
||||
|
||||
|
||||
class NetBoxUtilitiesConfig(PluginConfig):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.core.cache import cache
|
||||
from django.db import OperationalError, ProgrammingError
|
||||
from django.db import OperationalError, ProgrammingError, transaction
|
||||
from netbox.plugins import get_plugin_config
|
||||
|
||||
from .models import UtilitiesSettings
|
||||
@@ -37,11 +37,14 @@ def _get_database_settings():
|
||||
runtime_settings = cache.get(SETTINGS_CACHE_KEY)
|
||||
if runtime_settings is None:
|
||||
try:
|
||||
runtime_settings = (
|
||||
UtilitiesSettings.objects.filter(singleton_id=1)
|
||||
.values("tenant_filter_enabled", "tenant_required")
|
||||
.first()
|
||||
)
|
||||
# The savepoint keeps an outer transaction (e.g. a running migration)
|
||||
# usable on PostgreSQL if the settings table does not exist yet.
|
||||
with transaction.atomic():
|
||||
runtime_settings = (
|
||||
UtilitiesSettings.objects.filter(singleton_id=1)
|
||||
.values("tenant_filter_enabled", "tenant_required")
|
||||
.first()
|
||||
)
|
||||
except (OperationalError, ProgrammingError):
|
||||
# The middleware can be imported before the first plugin migration.
|
||||
runtime_settings = None
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "netbox-utilities"
|
||||
version = "0.14.2"
|
||||
version = "0.14.3"
|
||||
description = "Navigation, tenant utilities, connection VLANs, partial-width racks, and bulk operations for NetBox 4.6/4.7"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
Reference in new issue
Block a user