Bug with contenttypes when models are removed - what approach to take?

140 views
Skip to first unread message

Diederik van der Boor

unread,
Dec 24, 2011, 12:55:53 PM12/24/11
to django-d...@googlegroups.com
Hi,

I've encountered a bug with the contenttypes framework when a model is
removed. You'll end up with a AttributeError in _add_to_cache():

'NoneType' object has no attribute '_meta'

That's because the ContentType still exists, byt ContentType.

I would like to solve it, yet I'm not sure about the recommended approach:
1. returning None for ContentType.objects.get_for_id() when the model does not
exist.
2. Raise an exception that the referenced model does not exist.

What is your idea on this?

This bug currently hits me because django-polymorphic (which I use) uses the
contenttype framework to upcast the models. As the models are removed, but the
contenttype still exists, making queries causes an AttributeError. When Django
returns a normal response, I'll see how to address this issue in django-
polymorphic too.

Best regards,

Diederik

Etienne Robillard

unread,
Dec 24, 2011, 6:50:56 PM12/24/11
to django-d...@googlegroups.com, vdb...@gmail.com

Hi,

I'm not sure this is not entirely related to django-polymorphic, yet
a traceback would have been helpful in understanding your code. :)

cheers,
E

--
Etienne Robillard
Lead Developer and Consultant
Green Tea Hackers Club
Email: anime...@gmail.com
Website: http://gthcfoundation.org

Florian Apolloner

unread,
Dec 25, 2011, 12:14:43 PM12/25/11
to django-d...@googlegroups.com


On Saturday, December 24, 2011 6:55:53 PM UTC+1, Diederik van der Boor wrote:

I've encountered a bug with the contenttypes framework when a model is
removed. You'll end up with a AttributeError in _add_to_cache():

        'NoneType' object has no attribute '_meta'

That's because the ContentType still exists, byt ContentType.


You are  supposed to run manage.py syncdb after removing model which will ask you if you want to delete stale contenttypes.


Cheers,
Florian
Reply all
Reply to author
Forward
0 new messages