mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-11 19:49:49 +02:00
Closes #21890: Deprecate the 'models' registry key
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user