1

I want to create a custom Django rest framework permission class by subclassing BasePermission, but I would also like it to be an abstract class. When doing so I get following error:

from abc import ABC, abstractmethod
from rest_framework.permissions import BasePermission


class CustomPermission(BasePermission, ABC):

    def has_permission(self, request, view):
        f1 = self.custom_func()
        return f1 == 1

    @abstractmethod
    def custom_func(self):
        ...

Error:

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Thanks

Update

Following also doesnt work. Generates same error:

class CustomPermission(BasePermission, ABC,metaclass=BasePermissionMetaclass):
    ... 
Aseem
  • 5,848
  • 7
  • 45
  • 69
  • Following advice from here https://stackoverflow.com/a/28727066/5833429 I can make it work but then it's not complaining about not implemented `abstractmethod`. – Tom Wojcik Feb 10 '21 at 11:08

0 Answers0