[Answered ]-Metaclass conflict with single inheritance

1πŸ‘

βœ…

The issue turned out to be unrelated to the actual admin class – The form used for add_form must be a subclass of ModelForm – in this case it was just a plain Form. When added to the page django introspects the form and attempts to inject a class in if it’s not a ModelForm, leading the to the metatype mismatch.

πŸ‘€gone

1πŸ‘

This could happen if an incorrect metaclass is getting chosen for UserAdmin, for example by __metaclass__ somehow getting inserted into the dict of the nascent class. Try the following test:

# force the correct metaclass:
metaclass = type(auth_admin.UserAdmin)
UserAdmin = metaclass("UserAdmin", (auth_admin.UserAdmin,), {})

If this works, it means a metaclass other than type(auth_admin.UserAdmin) is getting picked in your class statement. The culprit should be revealed by grepping Django sources and mixins for __metaclass__.

If this fails with the same error, it could be that the metaclass constructor is doing some class construction of its own, which fails because of a genuine multiple inheritance error. In that case, a stack trace should reveal where this occurs.

Leave a comment