From 54b4b3c4ce479bbeb9d5eeae62bfa6e2e79a9f90 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 18 Mar 2025 09:57:53 -0400 Subject: [PATCH 1/2] Fixes #169: Replicate the global search table for each branch --- netbox_branching/constants.py | 1 + netbox_branching/models/branches.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/netbox_branching/constants.py b/netbox_branching/constants.py index d90e811..10e3c40 100644 --- a/netbox_branching/constants.py +++ b/netbox_branching/constants.py @@ -14,6 +14,7 @@ # must be replicated for each branch to ensure proper functionality INCLUDE_MODELS = ( 'dcim.cablepath', + 'extras.cachedvalue', ) # Models for which branching support is explicitly disabled diff --git a/netbox_branching/models/branches.py b/netbox_branching/models/branches.py index 624ac06..830c8c6 100644 --- a/netbox_branching/models/branches.py +++ b/netbox_branching/models/branches.py @@ -4,6 +4,7 @@ from datetime import timedelta from functools import cached_property, partial +from django.apps import apps from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError @@ -518,15 +519,15 @@ def provision(self, user): cursor.execute( f"INSERT INTO {schema_table} SELECT * FROM {main_table}" ) - # Get the name of the sequence used for object ID allocations + # Get the name of the sequence used for object ID allocations (if one exists) cursor.execute( "SELECT pg_get_serial_sequence(%s, 'id')", [table] ) - sequence_name = cursor.fetchone()[0] # Set the default value for the ID column to the sequence associated with the source table - cursor.execute( - f"ALTER TABLE {schema_table} ALTER COLUMN id SET DEFAULT nextval(%s)", [sequence_name] - ) + if sequence_name := cursor.fetchone()[0]: + cursor.execute( + f"ALTER TABLE {schema_table} ALTER COLUMN id SET DEFAULT nextval(%s)", [sequence_name] + ) # Commit the transaction cursor.execute("COMMIT") From caf127fd9fdd57743d16cdfc84120fb4661049d4 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 18 Mar 2025 10:01:34 -0400 Subject: [PATCH 2/2] Cleanup --- netbox_branching/models/branches.py | 1 - 1 file changed, 1 deletion(-) diff --git a/netbox_branching/models/branches.py b/netbox_branching/models/branches.py index 830c8c6..882e6e6 100644 --- a/netbox_branching/models/branches.py +++ b/netbox_branching/models/branches.py @@ -4,7 +4,6 @@ from datetime import timedelta from functools import cached_property, partial -from django.apps import apps from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError