question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
zymergen-stiancommented, Aug 13, 2020

Also I want to point out that https://github.com/FactoryBoy/factory_boy/commit/7a2d57778f1d8167cbcfb2cf6d61558d7ee39abf 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?

2reactions
zymergen-stiancommented, Aug 13, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python import error "module 'factory' has no attribute 'fuzzy'"
When you import a Python module (your import factory ), you can then access directly what is declared in that module (e.g factory.Factory...
Read more >
factory.django — Factory Boy rbarrois-guide documentation
__name__)) try: manager = model_class.objects except AttributeError: # When inheriting from an abstract model with a custom # manager, the class has no...
Read more >
Improve your Django tests with fakes and factories - HackSoft
Improve your Django tests with fakes and factories: Advanced usage ... AttributeError: 'Roster' object has no attribute 'start_after'.
Read more >
AttributeError: 'module' object has no attribute '_handlerList'
As I suspected, there is a problem with the logging module, which is probably shadowed, i.e. when Django performs "import logging" it imports...
Read more >
Run.py error; module 'collections' has no attribute 'Iterable'
... "C:\Program Files\MongoDB\M220P\mflix-python\mflix\factory.py", line 12, ... Iterable)): **AttributeError: module 'collections' has no ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found