nautobot-app-ssot icon indicating copy to clipboard operation
nautobot-app-ssot copied to clipboard

`NautobotModel.get_from_db()` doesn't work for custom fields and many to many relationships

Open Kircheneer opened this issue 1 year ago • 2 comments

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.

Kircheneer avatar Dec 04 '23 14:12 Kircheneer

Fixed for custom fields with #350

Kircheneer avatar Feb 27 '24 16:02 Kircheneer

Also, #361

Kircheneer avatar Feb 27 '24 16:02 Kircheneer