Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: ImportError of ModelFactory #356

Closed
1 of 4 tasks
ValentinaDrozdova opened this issue Sep 13, 2023 · 6 comments · Fixed by #359 or #370
Closed
1 of 4 tasks

Bug: ImportError of ModelFactory #356

ValentinaDrozdova opened this issue Sep 13, 2023 · 6 comments · Fixed by #359 or #370
Assignees
Labels
bug Something isn't working

Comments

@ValentinaDrozdova
Copy link

ValentinaDrozdova commented Sep 13, 2023

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

image

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
Fund with Polar
@ValentinaDrozdova ValentinaDrozdova added the bug Something isn't working label Sep 13, 2023
@Goldziher
Copy link
Contributor

What version of attrs do you have installed?

@ValentinaDrozdova
Copy link
Author

ValentinaDrozdova commented Sep 13, 2023

What version of attrs do you have installed?

21.4.0

UPD: updated the version to the latest. No more error. Thank you :)

@guacs
Copy link
Member

guacs commented Sep 13, 2023

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:

  1. pin attrs to a minimum version
  2. change the AttrsFactory implementation to support the older versions

@guacs guacs reopened this Sep 13, 2023
@guacs
Copy link
Member

guacs commented Sep 14, 2023

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.

@Goldziher
Copy link
Contributor

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.

Yes pls

@guacs
Copy link
Member

guacs commented Sep 16, 2023

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.

@guacs guacs reopened this Sep 16, 2023
@guacs guacs self-assigned this Sep 16, 2023
@guacs guacs mentioned this issue Sep 17, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants