Opened 5 years ago
Last modified 5 years ago
#31282 closed Bug
RelatedManager.set(..) no longer accepts a list of PKs — at Version 2
Reported by: | Yu Li | Owned by: | nobody |
---|---|---|---|
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 (2)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
However, this works fine: