get_for_model() method on ObjectType manager does not reliably resolve instances to classes #11507

Closed
opened 2025-12-29 21:46:09 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Aug 20, 2025).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.4.0-beta1

Python Version

3.10

Steps to Reproduce

Reproduction for this is a bit contrived, as the issue surfaced during the application of migrations under niche circumstances, but ultimately it derives from calling ObjectType.objects.get_for_model(model) when an ObjectType record for the given model does not yet exist.

Expected Behavior

A new ObjectType record should be automatically created for the model.

Observed Behavior

An exception is raised:

AttributeError: type object 'ModelBase' has no attribute '_meta'

This is due to forcing resolution of the base class (line 78):

a59da37ac3/netbox/core/models/object_types.py (L74-L79)

Originally created by @jeremystretch on GitHub (Aug 20, 2025). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.4.0-beta1 ### Python Version 3.10 ### Steps to Reproduce Reproduction for this is a bit contrived, as the issue surfaced during the application of migrations under niche circumstances, but ultimately it derives from calling `ObjectType.objects.get_for_model(model)` when an ObjectType record for the given model does not yet exist. ### Expected Behavior A new ObjectType record should be automatically created for the model. ### Observed Behavior An exception is raised: ``` AttributeError: type object 'ModelBase' has no attribute '_meta' ``` This is due to forcing resolution of the base class (line 78): https://github.com/netbox-community/netbox/blob/a59da37ac3a41ed40b361dac3a1b17312a887076/netbox/core/models/object_types.py#L74-L79
adam added the type: bugstatus: acceptedbetaseverity: medium labels 2025-12-29 21:46:09 +01:00
adam closed this issue 2025-12-29 21:46:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11507