if cls._get_build_context(_build_context).get("factory_use_construct"):
On another note, it seems this issue has highlighted the fact that the build context isn't being passed down to factories for models in collection fields when using .coverage() (see traceback for the snippet in the mcve)
EDIT: Reading the PR that introduced this... Seems like this has already been raised.
@guacs @Reskov
MCVE
from pydantic import BaseModel
from polyfactory.factories.pydantic_factory import ModelFactory
class T(BaseModel):
i: int
class L(BaseModel):
l: list[T]
list(ModelFactory.create_factory(L).coverage())
Logs
@classmethod
def _create_model(cls, _build_context: PydanticBuildContext, **kwargs: Any) -> T:
"""Create an instance of the factory's __model__
:param _build_context: BuildContext instance.
:param kwargs: Model kwargs.
:returns: An instance of type T.
"""
> if _build_context.get("factory_use_construct"):
E AttributeError: 'NoneType' object has no attribute 'get'
.venv/lib/python3.10/site-packages/polyfactory/factories/pydantic_factory.py:504: AttributeError
Release Version
2.16.1
Platform
[X] Linux
[ ] Mac
[ ] Windows
[ ] Other (Please specify in the description above)
Description
I'm getting errors from the
ModelFactory._create_model
function which is not handling when the passed in build context isNone
: https://github.com/litestar-org/polyfactory/pull/549/files#diff-58f44001d9e3d42e5c8fc55d621181dc66f78b37b46a414bb1bf6b6dd1d2bcbbR504Should that line be:
On another note, it seems this issue has highlighted the fact that the build context isn't being passed down to factories for models in collection fields when using
.coverage()
(see traceback for the snippet in the mcve)EDIT: Reading the PR that introduced this... Seems like this has already been raised.
@guacs @Reskov
MCVE
Logs
Release Version
2.16.1
Platform