mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Merge commit '19dcdc5442728451540d764f674f299cc2a80d48' into pk_related
* commit '19dcdc5442728451540d764f674f299cc2a80d48': Try to recover an object by its ID before duplicating it.
This commit is contained in:
commit
55dfbcd42a
|
@ -526,6 +526,11 @@ class BaseSerializer(WritableField):
|
||||||
# Determine which object we're updating
|
# Determine which object we're updating
|
||||||
identity = self.get_identity(item)
|
identity = self.get_identity(item)
|
||||||
self.object = identity_to_objects.pop(identity, None)
|
self.object = identity_to_objects.pop(identity, None)
|
||||||
|
if not self.object and getattr(self.opts, 'model', None):
|
||||||
|
try:
|
||||||
|
self.object = self.opts.model.objects.get(id=self.get_identity(item))
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
if self.object is None and not self.allow_add_remove:
|
if self.object is None and not self.allow_add_remove:
|
||||||
ret.append(None)
|
ret.append(None)
|
||||||
errors.append({'non_field_errors': ['Cannot create a new item, only existing items may be updated.']})
|
errors.append({'non_field_errors': ['Cannot create a new item, only existing items may be updated.']})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user