#33011: my_model.manyrelation_set.all() return empty value
-------------------------------------+-------------------------------------
Reporter: Floréal Cabanettes | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: model set querying | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* resolution: => needsinfo
Comment:
Hi Floréal.
I can't see how to reproduce this with the info given. (There must be
something else going on in your project.)
Django's `model_fields` tests use these models:
{{{
class Foo(models.Model):
a = models.CharField(max_length=10)
d = models.DecimalField(max_digits=5, decimal_places=3)
def get_foo():
return Foo.objects.get(id=1).pk
class Bar(models.Model):
b = models.CharField(max_length=10)
a = models.ForeignKey(Foo, models.CASCADE, default=get_foo,
related_name='bars')
}}}
This is equivalent to yours here I think (in the relevant respects).
Adding this test passes:
{{{
diff --git a/tests/model_fields/test_foreignkey.py
b/tests/model_fields/test_foreignkey.py
index 0cd6d62a55..c51b6d978a 100644
--- a/tests/model_fields/test_foreignkey.py
+++ b/tests/model_fields/test_foreignkey.py
@@ -12,6 +12,14 @@ from .models import Bar, FkToChar, Foo,
PrimaryKeyCharModel
class ForeignKeyTests(TestCase):
+ def test_reverse_relation(self):
+ a = Foo.objects.create(id=1, a='abc', d=Decimal('12.34'))
+ # Bar FK defaults to Foo with id=1
+ b = Bar.objects.create(b='bcd')
+ c = Bar.objects.create(b='bcd')
+ d = Bar.objects.create(b='bcd')
+ self.assertSequenceEqual(a.bars.all(), [b, c, d])
+
def test_callable_default(self):
"""A lazy callable may be used for ForeignKey.default."""
a = Foo.objects.create(id=1, a='abc', d=Decimal('12.34'))
}}}
This is already covered elsewhere in the test suite (many times).
Can I ask you to provide a minimal reproduce of your issue?
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/33011#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.b644dbf75ccf8d3dc405d817533989c0%40djangoproject.com.