#31282: RelatedManager.set(..) no longer accepts a list of PKs
-------------------------------+--------------------------------------
     Reporter:  YLiLarry       |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Uncategorized  |                  Version:  3.0
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by YLiLarry:

Old description:

> {{{
> >>> i = ProductImage.objects.get(pk=100)
> >>> p.images.set([100])
> 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 100

New description:

 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',
     )
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31282#comment:2>
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/066.3c94c8972714f4458bbaa26354f69cbe%40djangoproject.com.

Reply via email to