-
-
Notifications
You must be signed in to change notification settings - Fork 460
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reverse relation is lost for abstract models with custom querysets #652
Comments
Great to hear! I would be happy to help.
Ask any questions you have! 👍 |
I've managed to make a bit of progress on this, but would appreciate any help as I am a bit stuck. From what I can tell, the root of the problem is when the This should be being set by the I have managed to make some progress in the commit here by making sure that we always look for generated managers. This makes things work when we change the example above to: from django.db import models
class AbstractLogQuerySet(models.QuerySet):
pass
class Transaction(models.Model):
pass
# Declare the queryset manager outside the model, and use from_queryset
AbstractLogQSManager = models.Manager.from_queryset(AbstractLogQuerySet)
class AbstractLog(models.Model):
objects = AbstractLogQSManager()
class Meta:
abstract=True
class TransactionLog(AbstractLog):
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE, related_name="logs")
Transaction().logs
# No output - so everything is fine However, it still does not work when the manager declaration is inline in the I guess my confusion boils down to: "is there a way to make sure that |
You try to |
@leamingrad, all of your test cases now pass on master. Could you please re-test to confirm the issue you encountered is now fixed? |
Thanks for this - just reran my tests locally that were reproducing the issue and I can confirm that this is now fixed 🎉 |
As someone living in Leningrad, I appreciate your username @leamingrad 😆 |
What's wrong
The reverse relation to a concrete subclass of an abstract model that uses a custom queryset is not being populated by
django-stubs
.A full set of test cases that illustrate the situation are in a commit here that I added on top of the latest master.
Since an example is worth a thousand words:
Interestingly, the problem seems to be specific to querysets being used to make managers:
I'm happy to help with a fix, but to be honest I have no idea where to start.
System information
I've seen this on multiple Python/Django/mypy/django-stubs versions but the test cases are written against:
python
version: 3.9.2django
version:3.2.4mypy
version: 0.910django-stubs
version: HEAD(Apologies if this is a duplicate - I looked and there seem to be similar issues but not this exact one)
The text was updated successfully, but these errors were encountered: