mirror of https://github.com/django/django.git
[1.8.x] Fixed #24611 -- Fixed update() crash with related UUID pk object.
Backport of 923da0274a
from master
This commit is contained in:
parent
3928270495
commit
496800b3bf
1
AUTHORS
1
AUTHORS
|
@ -311,6 +311,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
Jason Yan <tailofthesun@gmail.com>
|
||||
Javier Mansilla <javimansilla@gmail.com>
|
||||
Jay Parlar <parlar@gmail.com>
|
||||
Jay Wineinger <jay.wineinger@gmail.com>
|
||||
J. Clifford Dyer <jcd@sdf.lonestar.org>
|
||||
jcrasta@gmail.com
|
||||
jdetaeye
|
||||
|
|
|
@ -1006,7 +1006,10 @@ class SQLUpdateCompiler(SQLCompiler):
|
|||
raise FieldError("Aggregate functions are not allowed in this query")
|
||||
elif hasattr(val, 'prepare_database_save'):
|
||||
if field.rel:
|
||||
val = val.prepare_database_save(field)
|
||||
val = field.get_db_prep_save(
|
||||
val.prepare_database_save(field),
|
||||
connection=self.connection,
|
||||
)
|
||||
else:
|
||||
raise TypeError("Database is trying to update a relational field "
|
||||
"of type %s with a value of type %s. Make sure "
|
||||
|
|
|
@ -38,3 +38,6 @@ Bugfixes
|
|||
|
||||
* Prevented arbitrary file inclusions in :mod:`~django.contrib.admindocs`
|
||||
(:ticket:`24625`).
|
||||
|
||||
* Fixed a crash with ``QuerySet.update()`` on foreign keys to instances with
|
||||
``uuid`` primary keys (:ticket:`24611`).
|
||||
|
|
|
@ -129,3 +129,20 @@ class TestAsPrimaryKey(TestCase):
|
|||
RelatedToUUIDModel.objects.create(uuid_fk=pk_model)
|
||||
related = RelatedToUUIDModel.objects.get()
|
||||
self.assertEqual(related.uuid_fk.pk, related.uuid_fk_id)
|
||||
|
||||
def test_update_with_related_model_instance(self):
|
||||
# regression for #24611
|
||||
u1 = PrimaryKeyUUIDModel.objects.create()
|
||||
u2 = PrimaryKeyUUIDModel.objects.create()
|
||||
r = RelatedToUUIDModel.objects.create(uuid_fk=u1)
|
||||
RelatedToUUIDModel.objects.update(uuid_fk=u2)
|
||||
r.refresh_from_db()
|
||||
self.assertEqual(r.uuid_fk, u2)
|
||||
|
||||
def test_update_with_related_model_id(self):
|
||||
u1 = PrimaryKeyUUIDModel.objects.create()
|
||||
u2 = PrimaryKeyUUIDModel.objects.create()
|
||||
r = RelatedToUUIDModel.objects.create(uuid_fk=u1)
|
||||
RelatedToUUIDModel.objects.update(uuid_fk=u2.pk)
|
||||
r.refresh_from_db()
|
||||
self.assertEqual(r.uuid_fk, u2)
|
||||
|
|
Loading…
Reference in New Issue