Skip to content

Bug: model_from_dict fails if dict has key called 'model' #668

@bmoregeo

Description

@bmoregeo

Description

I have a model with an attribute of 'model'. This bombs out model_from_dict as it has a param named 'model' and this causes a conflict with the attribute on the passed in dict.

Our workaround is to rename our attribute to 'model_' to get around the keyword argument conflict.

There are some fixes I can think off the top of my head, but they also have their issues

  • rename the model input parameter to something less likely to conflict
  • allow for a dictionary to be input as a kw argument in addition to the current method

URL to code causing the issue

No response

MCVE

class UUIDCar(UUIDAuditBase):
    """The car domain model."""
    make: Mapped[str] = mapped_column(String(length=50))
    model: Mapped[str] = mapped_column(String(length=50))

def test_dict_has_model_attribute() -> None:

    from tests.fixtures.uuid.models import UUIDCar

    data = {
        "make": "Advanced",
        "model": "Alchemy"
    }
    car = model_from_dict(UUIDCar, **data)

    assert car.make == "Advanced"
    assert car.model == "Alchemy"

Steps to reproduce

1. Create class with an attribute 'model'
2. Attempt to instantiate it with model_from_dict

Screenshots

"In the format of: ![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

Package Version

1.8.2

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions