-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError on django startup #955
Comments
What happens if you drop the (More: any chance you could reduce this to a minimal example so I can have a play myself?) |
Hi! It works without the ABC inheritance 馃憤 |
The minimal example:
|
A minimal example to recreate the class Foo(abc.ABC, FilterView):
pass |
This doesn't look specific to django-filter, more that a class cannot inherit two separate metaclasses. class AMeta(type): pass
class BMeta(type): pass
class A(metaclass=AMeta): pass
class B(metaclass=BMeta): pass
# fails with metaclass error
class C(A, B): pass
# passes
class CMeta(AMeta, BMeta): pass
class C(A, B, metaclass=CMeta): pass The relevant change in 2.x is that class MyMeta(ABCMeta, type(FilterView)):
pass
class ForventetRegnskab(LoginRequiredMixin, UserPassesTestMixin, FilterView, metaclass=MyMeta):
pass
`` |
Thank you for the write-up @rpkilby! |
Hi both of you! @rpkilby very clear answer - and your solution works for the record! 馃 All the best, Henrik |
Hi again! I Hope you have the time to clarify one thing: Why do you use type(FilterView) and not just FilterView? |
The type of a class is it's metaclass. i.e., the default metaclass is
Not exactly, it just gets the metaclass (not creating a new metaclass). This is an alternative to referencing
It would apply to the class and its subclasses, unless overridden by another metaclass. |
Thanks again, that was helpful. |
Everything in Python is an object, and everything is constructed from a class. i.e., the class of an instance is its class, the class of a class is its metaclass. The only special case is the base
I mistyped. A class cannot be created from two metaclasses. It can however, be created from a metaclass that inherits multiple other metaclasses. This is similar to how you cannot instantiate an object with two classes. You would need to create one class that inherits both and instantiate the object from that. Class creation is the same way.
It's metaclass is |
Thank you! Everything makes sense now - yes, I did the type checking it adds up - it is not magic |
First of all, thank you for maintaining this amazing package 馃憤
I just updated django-filter 1.1.0 to 2.0.0 and now the following CBV fails at django startup:
Each subclass implements its own filterset_class and queryset. Here is an example:
I get this error at startup:
File "[...]\oekonomistyring\forventet_regnskab\views.py", line 18, in
class ForventetRegnskab(ABC, LoginRequiredMixin, UserPassesTestMixin, FilterView):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
Hmmm... !
Is this behavior wanted or is this a bug?
The text was updated successfully, but these errors were encountered: