litestar-org / polyfactory

Simple and powerful factories for mock data generation
https://polyfactory.litestar.dev/
MIT License
1.06k stars 83 forks source link

Bug: TypeError: should_set_field_value() got multiple values for argument 'field_name' #150

Closed Skyross closed 1 year ago

Skyross commented 1 year ago

Description

Looks like now it is not possible to build example of the model using field_name and model_field names without getting this error:

Traceback (most recent call last):
  File "/Users/skyross/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/223.8836.43/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/Users/skyross/Library/Caches/pypoetry/virtualenvs/...-py3.8/lib/python3.8/site-packages/pydantic_factories/factory.py", line 739, in build
    if cls.should_set_field_value(field_name, model_field, **kwargs):
TypeError: should_set_field_value() got multiple values for argument 'field_name'

URL to code causing the issue

No response

MCVE

from pydantic import BaseModel
from pydantic_factories import ModelFactory
class Model(BaseModel):
    field_name: str
    limit: int

type(Model.__name__, (ModelFactory,), {"__model__": Model}).build()

Steps to reproduce

1. Execute MCVE snippet
2. See error

Screenshots

No response

Logs

No response

Starlite Version

pydantic_factories-1.17.2

Platform

Goldziher commented 1 year ago

please check this using main and update the issue as required.

Skyross commented 1 year ago

It is fixed! Tested with polyfactory=2.0.0 and it is working correctly:

from pydantic import BaseModel
from polyfactory.factories.pydantic_factory import ModelFactory

class Model(BaseModel):
    field_name: str
    limit: int

type(Model.__name__, (ModelFactory,), {"__model__": Model}).build()