#31095: Django Related Manager set method
-------------------------------------+-------------------------------------
               Reporter:  TZanke     |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 To update a complete list of foreignkeys, we use set() method of
 relatedmanager to get a performance gain and avoid remove and add keys not
 touched by user.

 But today i noticed our database removes all foreignkeys and adds them
 again. After some debugging i found the issue in this condition:
 
https://github.com/django/django/blob/master/django/db/models/fields/related_descriptors.py#L1004

 Our form returns all Foreignkeys as list of strings in cleaned_data, but
 the strings do not match the pk (int). After converting the strings to
 int, before calling set(), fixes the problem.

 Question:
 How to avoid this issue? Maybe all code usages of set() are using lists of
 strings, maybe not. I dont know at the moment.
 Is is possible Django fixes this issue? Should Django fix the issue? Maybe
 strings should raise an exception?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31095>
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/049.078726cfeb116a813c448fd1ad3e24ab%40djangoproject.com.

Reply via email to