#8467: For ManyToMany manager, we should convert objects being added or removed
to
the pk type if they are not.
-------------------------------------+-------------------------------------
Reporter: Wonlay | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Duplicate entry, | Triage Stage: Accepted
add, remove, ManyToManyField |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by akaariai):
I think we should fix this on the basis that using b.a.add('1') works
partly, but the duplication check doesn't work. Either we should reject
strings where ints are required, or handle type coercions fully.
To fix this, we should coerce the input values to right type right at the
beginning of add() and remove(). The same applies likely also to reverse
foreign key sets. Still, we need to convert to the primary key type of the
target model, that is, the code should work also when A had a custom
primary key (for example, A.name was primary key).
Tests for m2m.add can be found from
https://github.com/akaariai/django/commit/b1308c114f601db2f3f0c8d76c55acd966a14672.
Similar tests should be added for .remove(), and for reverse foreign key
.add() and .remove().
--
Ticket URL: <https://code.djangoproject.com/ticket/8467#comment:11>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.9af7cfcb311afdce3e69879d7124d702%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.