Closes #21890: Deprecate the 'models' registry key

This commit is contained in:
Jeremy Stretch
2026-04-10 17:06:56 -04:00
parent 133ed53849
commit 903c478454
2 changed files with 13 additions and 3 deletions

View File

@@ -722,10 +722,10 @@ def register_models(*models):
for model in models: for model in models:
app_label, model_name = model._meta.label_lower.split('.') app_label, model_name = model._meta.label_lower.split('.')
# TODO: Remove in NetBox v4.5 # TODO: Remove in NetBox v4.7
# Register public models # Register public models (access the underlying dict directly to avoid triggering the deprecation warning)
if not getattr(model, '_netbox_private', False): if not getattr(model, '_netbox_private', False):
registry['models'][app_label].add(model_name) dict.__getitem__(registry, 'models')[app_label].add(model_name)
# Register applicable feature views for the model # Register applicable feature views for the model
if issubclass(model, ContactsMixin): if issubclass(model, ContactsMixin):

View File

@@ -9,6 +9,15 @@ class Registry(dict):
removed (though the value of each key is mutable). removed (though the value of each key is mutable).
""" """
def __getitem__(self, key): def __getitem__(self, key):
# TODO: Remove in NetBox v4.7
if key == 'models':
import warnings
warnings.warn(
'The "models" registry key is deprecated and will be removed in NetBox v4.7. Registered models can be '
'obtained by calling ObjectType.objects.public().',
DeprecationWarning,
stacklevel=2,
)
try: try:
return super().__getitem__(key) return super().__getitem__(key)
except KeyError: except KeyError:
@@ -29,6 +38,7 @@ registry = Registry({
'event_types': dict(), 'event_types': dict(),
'filtersets': dict(), 'filtersets': dict(),
'model_features': dict(), 'model_features': dict(),
# TODO: Remove in NetBox v4.7
'models': collections.defaultdict(set), 'models': collections.defaultdict(set),
'plugins': dict(), 'plugins': dict(),
'request_processors': list(), 'request_processors': list(),