nautobot-app-ssot
nautobot-app-ssot copied to clipboard
`NautobotModel.get_from_db()` doesn't work for custom fields and many to many relationships
Environment
- Python version:
- Nautobot version: 1/2
- nautobot-ssot version: 1.6/2.0
Expected Behavior
When defining a model like this:
from typing import Annotated
from nautobot.tenancy.models import Tenant
from nautobot_ssot.contrib import NautobotModel, CustomFieldAnnotation
class TenantModel(NautobotModel):
_model = Tenant
_modelname = "tenant"
_identifiers = ("name", "line_of_business",)
name: str
line_of_business: Annotated[str, CustomFieldAnnotation(name="Line of Business")]
I expect TenantModel.get_from_db()
to still work. However, it will issue a query like Tenant.objects.get(name="example", line_of_business="Shipping")
which will crash. Instead, we should use the mapping from the CustomFieldAnnotation
.
Observed Behavior
There is a crash, because the field line_of_business
doesn't exist.
Steps to Reproduce
Described above.
Fixed for custom fields with #350
Also, #361