Skip to content

Commit

Permalink
Closes #101: Permit (but warn about) database queries issued before b…
Browse files Browse the repository at this point in the history
…ranching support has been initialized
  • Loading branch information
jeremystretch committed Sep 11, 2024
1 parent d5193bd commit 1ff288e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions netbox_branching/database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from netbox.registry import registry

from .contextvars import active_branch
Expand All @@ -14,6 +16,11 @@ class BranchAwareRouter:
the active branch (if any).
"""
def _get_db(self, model, **hints):
# Warn & exit if branching support has not yet been initialized
if 'branching' not in registry['model_features']:
warnings.warn(f"Routing database query for {model} before branching support is initialized.")
return

# Bail if the model does not support branching
app_label, model_name = model._meta.label.lower().split('.')
if model_name not in registry['model_features']['branching'].get(app_label, []):
Expand Down

0 comments on commit 1ff288e

Please sign in to comment.