Bug: ImportError of ModelFactory
ValentinaDrozdova opened this issue · 6 comments
Description
I am importing ModelFactory and get an error when starting the application about ImportError
URL to code causing the issue
No response
MCVE
# from polyfactory.factories.pydantic_factory import ModelFactory
Steps to reproduce
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
Screenshots
Logs
from polyfactory.factories.pydantic_factory import ModelFactory
File "/home/user/.cache/pypoetry/virtualenvs/message-proccesor-imlqFjNq-py3.10/lib/python3.10/site-packages/polyfactory/__init__.py", line 2, in <module>
from .factories import BaseFactory
File "/home/user/.cache/pypoetry/virtualenvs/message-proccesor-imlqFjNq-py3.10/lib/python3.10/site-packages/polyfactory/factories/__init__.py", line 1, in <module>
from polyfactory.factories.base import BaseFactory
File "/home/user/.cache/pypoetry/virtualenvs/message-proccesor-imlqFjNq-py3.10/lib/python3.10/site-packages/polyfactory/factories/base.py", line 859, in <module>
_register_builtin_factories()
File "/home/user/.cache/pypoetry/virtualenvs/message-proccesor-imlqFjNq-py3.10/lib/python3.10/site-packages/polyfactory/factories/base.py", line 854, in _register_builtin_factories
import_module(module)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/user/.cache/pypoetry/virtualenvs/message-proccesor-imlqFjNq-py3.10/lib/python3.10/site-packages/polyfactory/factories/attrs_factory.py", line 20, in <module>
T = TypeVar("T", bound=attrs.AttrsInstance)
AttributeError: module 'attrs' has no attribute 'AttrsInstance'
Release Version
polyfactory = "^2.8.1"
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Funding
- If you would like to see an issue prioritized, make a pledge towards it!
- We receive the pledge once the issue is completed & verified
What version of attrs do you have installed?
What version of attrs do you have installed?
21.4.0
UPD: updated the version to the latest. No more error. Thank you :)
Hm..so we have a minimum version of attrs
that is needed for our AttrsFactory
implementation to work huh? I'm going to reopen this so that we can find a fix for that. I think there are two options:
- pin
attrs
to a minimum version - change the
AttrsFactory
implementation to support the older versions
I just checked and it seems the AttrsFactory
only works for version 22.4+. @Goldziher, should we do a release with the minimum requirements for attrs
being set to 22.4.0
?
UPDATE: The current tests will fail for 22.4, but that is due to the tests themselves being only suitable for v23+ and not an issue with AttrsFactory
. If the tests are changed to use the correct API as per 22.4, then the tests do pass for all versions from 22.4 onwards.
I just checked and it seems the
AttrsFactory
only works for version 22.4+. @Goldziher, should we do a release with the minimum requirements forattrs
being set to22.4.0
?UPDATE: The current tests will fail for 22.4, but that is due to the tests themselves being only suitable for v23+ and not an issue with
AttrsFactory
. If the tests are changed to use the correct API as per 22.4, then the tests do pass for all versions from 22.4 onwards.
Yes pls
This is still not resolved as stated here.
Quoting it here for reference:
Unfortunately this is not a complete fix. I have project and use polyfactory with pydantic. Attrs package is included, because of other dependencies (I personally don't use it and have no direct dependency). When running unit tests I still get error AttributeError: module 'attrs' has no attribute 'AttrsInstance'. The version is kept low because one of my dependency wants lower version.