Strange traceback with django-polymorphic from github

853 views
Skip to first unread message

Benjamin Wohlwend

unread,
Nov 30, 2010, 2:12:12 AM11/30/10
to django-polymorphic
Hi,

I used django-polymorphic for a project and really love it. With the
current version from github, I get a strange traceback, though:

TypeError: Error when calling the metaclass bases
issubclass() arg 2 must be a class or tuple of classes

Full traceback is at http://dpaste.com/hold/281393/. After fiddling
around for a couple of hours, this patch helped:

diff --git a/polymorphic/base.py b/polymorphic/base.py
index 7210558..4e742e0 100644
--- a/polymorphic/base.py
+++ b/polymorphic/base.py
@@ -65,6 +65,7 @@ class PolymorphicModelBase(ModelBase):
# get first user defined manager; if there is one, make it
the _default_manager
user_manager = self.get_first_user_defined_manager(attrs)
if user_manager:
+ user_manager.model = new_class
def_mgr = user_manager._copy_to_model(new_class)
#print '## add default manager', type(def_mgr)
new_class.add_to_class('_default_manager', def_mgr)

I found it with pure trial & error, I don't really grok the code
there :-) But it made the exception disappear and has no bad effects,
at least as far as I can tell.

Anybody else seeing this?

Kind regards,
Benjamin

Bert Constantin

unread,
Nov 30, 2010, 3:22:08 PM11/30/10
to django-polymorphic
Hello Benjamin!

> TypeError: Error when calling the metaclass bases
> issubclass() arg 2 must be a class or tuple of classes

From looking at the full traceback it seems that a custom manager
is defined in a polymorphic model
(probably Publication(DatedObject)).

django_polymorphic then wants to copy this manager but
Django's _copy_to_model function complains that this manager's
member variable .model is not set correctly.

>I found it with pure trial & error, I don't really grok the code
>there :-) But it made the exception disappear and has no bad effects,
>at least as far as I can tell.

You basically did the right thing as user_manager.model should
indeed be new_class. However, the question remains why it isn't
already set correctly in the first place.

It would be interesting if you could replace the content of
polymorphic/base.py with the content shown here:
https://gist.github.com/722277

You also should be able to download the file directly:
wget https://gist.github.com/raw/722277/base.py

This modified base.py just prints some more info about the affected
model and manager (via sys.stderr.write) directly before the
exception trace (three lines beginning with "# first user defined
manager for model").

Could you then post the result (these three lines)?

I'm also interested in the class definitions for the models
Publication and DatedObject and for the custom manager.
Could you post them (or send them via email)? Perhaps I can see
something there that sheds more light onto this problem.

Kind Regards,
Bert Constantin

Benjamin Wohlwend

unread,
Nov 30, 2010, 4:44:08 PM11/30/10
to django-po...@googlegroups.com
Hi Bert,

thanks for looking into this!

On Tue, Nov 30, 2010 at 9:22 PM, Bert Constantin <bert.co...@gmx.de> wrote:
>
> Hello Benjamin!
>
> >    TypeError: Error when calling the metaclass bases
> >        issubclass() arg 2 must be a class or tuple of classes
>
> From looking at the full traceback it seems that a custom manager
> is defined in a polymorphic model
> (probably Publication(DatedObject)).

Dang, I should have thought about mentioning that a custom Manager is
involved. Sorry.


> It would be interesting if you could replace the content of
> polymorphic/base.py with the content shown here:
> https://gist.github.com/722277
>
> You also should be able to download the file directly:
> wget https://gist.github.com/raw/722277/base.py
>
> This modified base.py just prints some more info about the affected
> model and manager (via sys.stderr.write) directly before the
> exception trace (three lines beginning with "# first user defined
> manager for model").
>
> Could you then post the result (these three lines)?

This is the output from ./manage.py shell

# first user defined manager for model "DatedObject":
# "objects": <polymorphic.manager.PolymorphicManager object at 0x299ad50>
# manager model: <class 'shared.models.DatedObject'>


# first user defined manager for model "Publication":
# "objects": <polymorphic.manager.PolymorphicManager object at 0x29a3190>
# manager model: <class 'publications.models.Publication'>


# first user defined manager for model "Publication":
# "objects": <polymorphic.manager.PolymorphicManager object at 0x2a2d7d0>
# manager model: None


> I'm also interested in the class definitions for the models
> Publication and DatedObject and for the custom manager.
> Could you post them (or send them via email)? Perhaps I can see
> something there that sheds more light onto this problem.

Sure, no problem. I shortened the class definitions for brevity's sake.

class PublishedManager(PolymorphicManager):
def get_query_set(self):
return super(PublishedManager, self).get_query_set().filter(publish=True)

class DatedObject(PolymorphicModel):
publish = models.BooleanField('publish', default=False)

objects = PolymorphicManager()
published = PublishedManager()
keywords = TaggableManager()

class Publication(DatedObject):
objects = PolymorphicManager()
batch = BatchManager()

BatchManager is from django-batch-select[1] and TaggableManager is
from django-taggit[2].

Thanks again for your time and great work!

Kind regards,
Benjamin

[1]: https://github.com/lilspikey/django-batch-select
[2]: https://github.com/alex/django-taggit

Benjamin Wohlwend

unread,
Feb 16, 2011, 8:51:31 AM2/16/11
to django-po...@googlegroups.com
Hi Bert,

On Tue, Nov 30, 2010 at 10:44 PM, Benjamin Wohlwend <piqu...@gmail.com> wrote:
>
> Hi Bert,
>
> thanks for looking into this!
>

Did you per chance have time to look into this problem? Do you need
any more information from me?

Kind regards,
Benjamin

martin.b...@googlemail.com

unread,
Nov 28, 2011, 2:35:10 AM11/28/11
to django-po...@googlegroups.com
I'm facing this same error.
As far as I can tell, first the testrunner loads all models, that try runs well but then in a test I import my module and this time .model is not set on the manager.
Reply all
Reply to author
Forward
0 new messages