Fix relationship issues with missing models for defined contenttypes #1121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #N/A
Fix a user-reported issue, the symptom being errors like the following when trying to edit a model instance:
The issue is that if we define a Relationship between core models and models from a plugin, then subsequently disable or uninstall the plugin, then the ContentTypes for the plugin still exist in the DB (and hence the Relationship still references them) but Nautobot doesn't know about the actual data models associated with those ContentTypes. Thus,
content_type.model_class()
returnsNone
rather than a model class as expected. We didn't have logic in the Relationships code to handle the case wheremodel_class
isNone
, resulting in the above error symptom.Rather than adding a signal or startup code to automatically delete Relationships that reference ContentTypes with no associated model classes, which could be problematic if for instance a plugin is only temporarily disabled to troubleshoot some other issue, I've just added error handling logic for the various cases I was able to reproduce with the above trigger:
DynamicModel[Multiple]ChoiceField
for the relationship, provide a simpleMultipleChoiceField
with no selectable options. (I wasn't able to figure out a straightforward way to omit the relationship from the edit form entirely in this case)