summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2019-11-21 20:02:57 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-22 09:08:10 +0100
commit379bf1a2d41494360d86bc3cf8adc482abca5d63 (patch)
treed5fc5003b27c7dd365b4ae7a9405d07910184d16 /django
parent8cc711999ab839c1a93cb228b35beac4a454fafc (diff)
Fixed #8467 -- Prevented crash when adding existent m2m relation with an invalid type.
This was an issue anymore on backends that allows conflicts to be ignored (Refs #19544) as long the provided values were coercible to the expected type. However on the remaining backends that don't support this feature, namely Oracle, this could still result in an IntegrityError. By attempting to coerce the provided values to the expected types in Python beforehand we allow the existing value set intersection in ManyRelatedManager._get_missing_target_ids to prevent the problematic insertion attempts. Thanks Baptiste Mispelon for triaging this old ticket against the current state of the master branch.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/fields/related_descriptors.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py
index 8468a0b01f..ec603bc8af 100644
--- a/django/db/models/fields/related_descriptors.py
+++ b/django/db/models/fields/related_descriptors.py
@@ -1064,7 +1064,7 @@ def create_forward_many_to_many_manager(superclass, rel, reverse):
(self.model._meta.object_name, obj)
)
else:
- target_ids.add(obj)
+ target_ids.add(target_field.get_prep_value(obj))
return target_ids
def _get_missing_target_ids(self, source_field_name, target_field_name, db, target_ids):