Remove the `models` key from the application registry (closes #21891)

Drops the deprecated registry['models'] key, the __getitem__ deprecation
warning, and the population code in register_model(). Registered models
should be retrieved via ObjectType.objects.public() instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeremy Stretch 2026-05-07 08:35:42 -04:00
parent 4d9e4838d4
commit 3b145a9c3d
4 changed files with 14 additions and 17 deletions

View File

@ -0,0 +1,13 @@
# NetBox v4.7
## v4.7.0 (FUTURE)
### Breaking Changes
### Enhancements
### Other Changes
* [#21891](https://github.com/netbox-community/netbox/issues/21891) - Remove the `models` key from the application registry (use `ObjectType.objects.public()` instead)
### REST API Changes

View File

@ -38,7 +38,7 @@ def preferences(request):
def registry(request):
"""
Adds NetBox registry items to the template context. Example: {{ registry.models.core }}
Adds NetBox registry items to the template context.
"""
return {
'registry': registry_,

View File

@ -723,11 +723,6 @@ def register_models(*models):
for model in models:
app_label, model_name = model._meta.label_lower.split('.')
# 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):
dict.__getitem__(registry, 'models')[app_label].add(model_name)
# Register applicable feature views for the model
if issubclass(model, ContactsMixin):
register_model_view(model, 'contacts', kwargs={'model': model})(

View File

@ -9,15 +9,6 @@ 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:
@ -39,8 +30,6 @@ registry = Registry({
'filtersets': dict(),
'model_actions': collections.defaultdict(set),
'model_features': dict(),
# TODO: Remove in NetBox v4.7
'models': collections.defaultdict(set),
'plugins': dict(),
'request_processors': list(),
'search': dict(),