fix: delete DATABASE after wrapping to avoid conflict
All checks were successful
Build and Push Docker Images / build (push) Successful in 6s

This commit is contained in:
2026-01-07 15:19:25 +00:00
parent 3ff6ace420
commit 93575f8569

View File

@@ -2,23 +2,15 @@
# NetBox Local Settings for netbox-branching plugin
# =============================================================================
# This file configures DynamicSchemaDict required by netbox-branching.
# It imports DATABASE from the NetBox Docker configuration and wraps it.
# It wraps the DATABASE from configuration.py into DATABASES.
# Placed in /etc/netbox/config/
# =============================================================================
import os
from netbox_branching.utilities import DynamicSchemaDict
# Build DATABASE dict from environment variables (same as netbox-docker does)
DATABASE = {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('DB_NAME', 'netbox'),
'USER': os.environ.get('DB_USER', ''),
'PASSWORD': os.environ.get('DB_PASSWORD', ''),
'HOST': os.environ.get('DB_HOST', 'localhost'),
'PORT': os.environ.get('DB_PORT', ''),
'CONN_MAX_AGE': int(os.environ.get('DB_CONN_MAX_AGE', 300)),
}
# Import DATABASE from the already-loaded configuration
# At this point, DATABASE is available in the global namespace from configuration.py
# We need to wrap it with DynamicSchemaDict and delete the original DATABASE
# Wrap DATABASES with DynamicSchemaDict for dynamic schema support
# This is required for netbox-branching plugin to function correctly
@@ -26,6 +18,9 @@ DATABASES = DynamicSchemaDict({
'default': DATABASE,
})
# Delete DATABASE to avoid "DATABASE and DATABASES may not be set together" error
del DATABASE
# Employ the custom database router for branch-aware queries
DATABASE_ROUTERS = [
'netbox_branching.database.BranchAwareRouter',