FactoryBoy fails when custom Manager is defined on abstract model #201

Closed
user0007 opened this Issue Apr 24, 2015 · 0 comments

Comments

Projects
None yet
2 participants
@user0007

factory-boy==2.5.2
django==1.8

FactoryBoy fails when custom Manager is defined on abstract model (it works fine with factory-boy==2.4.1). Example:

class CustomManager(models.Manager):
    pass

class BaseModel(models.Model):
    custom_objects = CustomManager()

    class Meta:
        abstract = True

class MyModel(BaseModel):
    pass

class MyModelFactory(factory.DjangoModelFactory):
    class Meta:
        model = MyModel

MyModelFactory.create()

Traceback (most recent call last):
File "/home/www/venvs/local/lib/python2.7/site-packages/factory/base.py", line 559, in create
return cls._generate(True, attrs)
File "/home/www/venvs/local/lib/python2.7/site-packages/factory/base.py", line 484, in _generate
obj = cls._prepare(create, *_attrs)
File "/home/www/venvs/local/lib/python2.7/site-packages/factory/base.py", line 459, in _prepare
return cls._create(model_class, *args, *_kwargs)
File "/home/www/venvs/local/lib/python2.7/site-packages/factory/django.py", line 144, in _create
manager = cls._get_manager(model_class)
File "/home/www/venvs/local/lib/python2.7/site-packages/factory/django.py", line 118, in _get_manager
manager = model_class.objects
AttributeError: type object 'MyModel' has no attribute 'objects'

@user0007 user0007 changed the title from AttributeError: type object 'MyModel' has no attribute 'objects' to FactoryBoy fails when custom Manager is defined on abstract model Apr 24, 2015

@rbarrois rbarrois added the Bug label Apr 25, 2015

@rbarrois rbarrois closed this in 0b5270e May 31, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment