TaggableManager from django-taggit fails in model creation #128

Merged
merged 1 commit into from Oct 16, 2013

2 participants

@rouge8

This is related to #89, but it looks like recent versions of taggit's TaggableManager now subclasses Field and provides has_default() == False.

../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:75: in make
>           return mommy.make(**attrs)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:241: in make
>       return self._make(commit=True, **attrs)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:277: in _make
>                   model_attrs[field.name] = self.generate_value(field)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:351: in generate_value
>       return generator(**generator_attrs)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:75: in make
>           return mommy.make(**attrs)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:241: in make
>       return self._make(commit=True, **attrs)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:277: in _make
>                   model_attrs[field.name] = self.generate_value(field)
../../.virtualenvs/dashboard/lib/python2.7/site-packages/model_mommy/mommy.py:342: in generate_value
>           raise TypeError('%s is not supported by mommy.' % field.__class__)
E           TypeError: <class 'taggit.managers.TaggableManager'> is not supported by mommy.

I can't provide a generator function for a custom field either, because the tags cannot be set from the model constructor.

I don't see an easy way to identify this kind of fake field. :/

@rouge8

You can however set the TaggableManager to blank=True, which fixes this for me, but possibly not in the general case.

@vandersonmota

Hi, thanks for the report! Which versions (Django, model_mommy and django-taggit) are you using?

@rouge8
model-mommy==1.1
django-taggit==0.10
Django==1.5.4
@vandersonmota

But even though in TaggableManager blank and null are False by default, you can create an object without issues, so It seems your solution is the right one. Maybe it's worth documenting it.

@rouge8

Yeah, documentation is probably the best solution.

@vandersonmota

If you want to do the honors.... well, just saying... =P

@rouge8

Sure. I'm heading out for the weekend now, but I'll get to it early Monday.

@vandersonmota

Thank you @rouge8 ! I'll close the issue when you send the PR.

@rouge8

I updated this issue with the PR. I think this is a start, but I'm not sure how much to generalize.

@vandersonmota vandersonmota merged commit f6e6598 into vandersonmota:master Oct 16, 2013

1 check passed

Details default The Travis CI build passed
@vandersonmota

Thanks!

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