From 1ed16c542ab7a7487066d63a33454a10fe098cc0 Mon Sep 17 00:00:00 2001 From: MrBlake Date: Tue, 13 Oct 2026 14:13:18 +0200 Subject: [PATCH] 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 --- netbox_utilities/__init__.py | 2 +- netbox_utilities/runtime.py | 15 +++++++++------ pyproject.toml | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/netbox_utilities/__init__.py b/netbox_utilities/__init__.py index 2bc9573..5224147 100644 --- a/netbox_utilities/__init__.py +++ b/netbox_utilities/__init__.py @@ -1,6 +1,6 @@ from netbox.plugins import PluginConfig, get_plugin_config -__version__ = "0.14.2" +__version__ = "0.14.3" class NetBoxUtilitiesConfig(PluginConfig): diff --git a/netbox_utilities/runtime.py b/netbox_utilities/runtime.py index 362cd0f..81fddff 100644 --- a/netbox_utilities/runtime.py +++ b/netbox_utilities/runtime.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 054c35c..2f9e86b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"