Django executing backward relation query occurred a maximum recursion depth exceeded error when I use Manager

Here's the code:

class CarSource

class CarSource(models.Model):
    status = models.CharField(max_length=1, blank=True, null=True)
    dealer = models.ForeignKey(Dealer, blank=True, null=True, \
                  on_delete=models.SET_NULL, related_name='cars', \
                  verbose_name=u'dealer own this car')
    objects = CarSourceManager()

class Dealer

class Dealer(models.Model):
    ...

class CarSourceManager:

class CarSourceManager(models.Manager):
    ''' Manage query in CarSource, filter data that was processed successfully.'''
    def get_query_set(self):
        return super(self.__class__, self).get_query_set().filter(status='S')

When I execute this:

from ... import Dealer
d = Dealer.objects.get(id = 2)
d.cars.all()

It occur error as below:

File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
File "/...path..of..error..file../apps/car/managers.py", line 9, in all
return super(self.__class__, self).all().filter(status='S')
RuntimeError: maximum recursion depth exceeded while calling a Python object

I overwrite the get_query_set of models.Manager in CarSourceManager, obviously, it continue call it self recursively. I've watched the code of Manager but can't figure it out, please help me.


ANSWERS:


See this answer:

Basically you can not use

super(self.__class__, self)

Use

super(CarSourceManager, self)

instead.

The related manager's self.__class__ is different from CarSourceManager therefore the loop.


This is exactly why you have to name the class explicitly when you call super:

return super(CarSourceManager, self).get_query_set().filter(status='S')


 MORE:


 ? When running a method from a Python superclass, how can I know the name of the child class that invoked it?
 ? Understanding @property decorator and inheritance
 ? IPython autoreload gives error for repeated calls to Python2 super()
 ? How do I properly inherit from a base class using Super() (Python 2/3)?
 ? How can I interpret this use of Python's super statement
 ? Append is overwriting existing data in list
 ? Using the python api in c not working on mac
 ? Not able to install quandl
 ? Google foobar minion labor shifts challange
 ? Pycharm type-hinting in __init__ does not work