#31282 closed Bug (fixed)
Docs for RelatedManager.set()/add()/remove() incorrectly states that the field the relation points to is acceptable for one-to-many relations.
Reported by: | Yu Li | Owned by: | Carlton Gibson |
---|---|---|---|
Component: | Documentation | Version: | 3.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Tobias Kunze | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
It seems that I can no longer pass a list of pks to RelatedManager.set(..).
Alternatively, passing a list of objects works as expected.
>>> p = Product.objects.all()[0] >>> p <Product: <Product pk=587 barcode=041390007019>> >>> p.images.set([1]) Traceback (most recent call last): File "<console>", line 1, in <module> File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/related_descriptors.py", line 750, in set self.add(*objs, bulk=bulk) File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/related_descriptors.py", line 656, in add check_and_update_obj(obj) File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/related_descriptors.py", line 648, in check_and_update_obj raise TypeError("'%s' instance expected, got %r" % ( TypeError: 'ProductImage' instance expected, got 1 class Product(m.Model): ... class ProductImage(m.Model): product = m.ForeignKey( Product, on_delete=m.CASCADE, related_name='images', )
Change History (9)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Description: | modified (diff) |
---|
comment:3 by , 5 years ago
Cc: | added |
---|---|
Component: | Uncategorized → Documentation |
Severity: | Normal → Release blocker |
Summary: | RelatedManager.set(..) no longer accepts a list of PKs → Docs for RelatedManager.set()/add()/remove() incorrectly states that the field the relation points to is acceptable for one-to-many relations. |
Triage Stage: | Unreviewed → Accepted |
RelatedManager.set()
for reverse relations has never accepted a list of IDs (unlike many-to-many).
There is a regression in docs introduced in a44a21a22f20c1a710670676fcca798dd6bb5ac0
Version 0, edited 5 years ago by (next)
comment:4 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
However, this works fine: