In the below example, you would expect foo.id
to be an int
When get_field_value
is called, field_meta.type_args
has correctly been identified as an int
- however, we end up calling the unwrapped annotation directly
This behaves as expected in polyfactory==2.2
, provided from __future__ import annotations
is not imported - and seems to have broken somewhere between there and polyfactory==2.3
https://github.com/litestar-org/polyfactory/blob/main/polyfactory/factories/base.py#L673
from polyfactory.factories import DataclassFactory
from sqlalchemy.orm import DeclarativeBase, Mapped, MappedAsDataclass, mapped_column
class Base(MappedAsDataclass, DeclarativeBase):
pass
class Foo(Base):
__tablename__ = "foo"
id: Mapped[int] = mapped_column(primary_key=True)
class FooFactory(DataclassFactory[Foo]):
__model__ = Foo
def test_factory():
foo = FooFactory.build()
print(type(foo))
assert isinstance(foo.id, int)
if __name__ == "__main__":
test_factory()
No response
No response
<class 'sqlalchemy.orm.base.Mapped'>
Traceback (most recent call last):
File "/app/tests/test_example.py", line 26, in <module>
test_factory()
File "/app/tests/test_example.py", line 22, in test_factory
assert isinstance(foo.id, int)
AssertionError
Python 3.11.4
polyfactory==2.8.0
SQLAlchemy==2.0.16
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too