mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #24611 -- Fixed update() crash with related UUID pk object.
This commit is contained in:
parent
872eb26f54
commit
923da0274a
1
AUTHORS
1
AUTHORS
@ -314,6 +314,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
|
||||
|
@ -1012,7 +1012,10 @@ class SQLUpdateCompiler(SQLCompiler):
|
||||
raise FieldError("Aggregate functions are not allowed in this query")
|
||||
elif hasattr(val, 'prepare_database_save'):
|
||||
if field.remote_field:
|
||||
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
Block a user