Compare commits

...

1 Commits

Author SHA1 Message Date
Jeremy Stretch
903c478454 Closes #21890: Deprecate the 'models' registry key 2026-04-10 17:06:56 -04:00
2 changed files with 13 additions and 3 deletions

View File

@@ -722,10 +722,10 @@ def register_models(*models):
for model in models:
app_label, model_name = model._meta.label_lower.split('.')
# TODO: Remove in NetBox v4.5
# Register public models
# TODO: Remove in NetBox v4.7
# Register public models (access the underlying dict directly to avoid triggering the deprecation warning)
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
if issubclass(model, ContactsMixin):

View File

@@ -9,6 +9,15 @@ class Registry(dict):
removed (though the value of each key is mutable).
"""
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:
return super().__getitem__(key)
except KeyError:
@@ -29,6 +38,7 @@ registry = Registry({
'event_types': dict(),
'filtersets': dict(),
'model_features': dict(),
# TODO: Remove in NetBox v4.7
'models': collections.defaultdict(set),
'plugins': dict(),
'request_processors': list(),