summaryrefslogtreecommitdiff
path: root/tests/db_functions
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2023-03-06 21:17:58 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-14 08:32:17 +0100
commitde0c7744be93800b2239eb061a2d8f7c669c05a8 (patch)
tree9de36d5d64eb184974257b0bc3d4def893ef2eb1 /tests/db_functions
parent254ad2e3450d8175170914f06af8358d2becc35b (diff)
downloaddjango-de0c7744be93800b2239eb061a2d8f7c669c05a8.tar.gz
Refs #28329 -- Fixed Cast() with ForeignKey to integer fields on MySQL.
Diffstat (limited to 'tests/db_functions')
-rw-r--r--tests/db_functions/comparison/test_cast.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/db_functions/comparison/test_cast.py b/tests/db_functions/comparison/test_cast.py
index afb6b473b9..80375cc389 100644
--- a/tests/db_functions/comparison/test_cast.py
+++ b/tests/db_functions/comparison/test_cast.py
@@ -76,6 +76,15 @@ class CastTests(TestCase):
numbers = Author.objects.annotate(cast_int=Cast("alias", field_class()))
self.assertEqual(numbers.get().cast_int, 1)
+ def test_cast_to_integer_foreign_key(self):
+ numbers = Author.objects.annotate(
+ cast_fk=Cast(
+ models.Value("0"),
+ models.ForeignKey(Author, on_delete=models.SET_NULL),
+ )
+ )
+ self.assertEqual(numbers.get().cast_fk, 0)
+
def test_cast_to_duration(self):
duration = datetime.timedelta(days=1, seconds=2, microseconds=3)
DTModel.objects.create(duration=duration)