1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #27595 -- Made ForeignKey.get_col() follow target chains.

Previously, foreign relationships were followed only one level deep which
prevents foreign keys to foreign keys from being resolved appropriately.
This was causing issues such as improper database value conversion for
UUIDField on SQLite because the resolved expression's output field's
internal type wasn't correct. Added tests to make sure unlikely foreign
reference cycles don't cause recursion errors.

Refs #24343.

Thanks oyooyo for the report and Wayne Merry for the investigation.
This commit is contained in:
Simon Charette
2018-10-22 09:49:34 -04:00
committed by Tim Graham
parent 4269648c0f
commit 5e3463f6bc
3 changed files with 37 additions and 2 deletions

View File

@@ -170,8 +170,12 @@ class TestAsPrimaryKey(TestCase):
self.assertEqual(r.uuid_fk, u2)
def test_two_level_foreign_keys(self):
gc = UUIDGrandchild()
# exercises ForeignKey.get_db_prep_value()
UUIDGrandchild().save()
gc.save()
self.assertIsInstance(gc.uuidchild_ptr_id, uuid.UUID)
gc.refresh_from_db()
self.assertIsInstance(gc.uuidchild_ptr_id, uuid.UUID)
class TestAsPrimaryKeyTransactionTests(TransactionTestCase):