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

AttributeError: module 'factory' has no attribute 'django' #769

Closed
ajbeach2 opened this issue Aug 13, 2020 · 5 comments
Closed

AttributeError: module 'factory' has no attribute 'django' #769

ajbeach2 opened this issue Aug 13, 2020 · 5 comments
Labels

Comments

@ajbeach2
Copy link

ajbeach2 commented Aug 13, 2020

Description

I cannot import the DjangoModelFactory as described in the documentation. I am using factory_boy 3.0.0 and python 3.8.3:

->pip freeze | grep factory
factory-boy==3.0.0
 ->python --version
Python 3.8.3

To Reproduce

From the documentation, https://factoryboy.readthedocs.io/en/3.0.0/orms.html I tried to create a class:

import factory
class UserFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = 'myapp.User'  # Equivalent to ``model = myapp.models.User``
        django_get_or_create = ('username',)

I get the following error:

AttributeError: module 'factory' has no attribute 'django
@zymergen-stian
Copy link

See https://github.com/FactoryBoy/factory_boy/blob/master/docs/changelog.rst#300-2020-08-12, you need to rewrite your imports.

@zymergen-stian
Copy link

Also I want to point out that 7a2d577 does not work.

try:
    import django
except ImportError:
    pass

This imports the "real django" pkg instead of the django.py of factoryboy. I believe the line should be from . import django?

@rbarrois
Copy link
Member

@zymergen-stian OH, thanks for the report! I'll fix it right away!

@rbarrois
Copy link
Member

Fixed in release 3.0.1.

@rbarrois rbarrois added the Bug label Aug 13, 2020
@zymergen-stian
Copy link

Thank you so much for the quick fix!! Verified it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants