From 776cee974933677730aef177eb5b5bdec3749c80 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 17 Jul 2017 21:12:27 +0200 Subject: Fixed #28391 -- Fixed Cast() with CharField and max_length on MySQL. Thanks Tim Graham for the review. --- tests/db_functions/test_cast.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/db_functions') diff --git a/tests/db_functions/test_cast.py b/tests/db_functions/test_cast.py index 70de20e5eb..bd4541bf06 100644 --- a/tests/db_functions/test_cast.py +++ b/tests/db_functions/test_cast.py @@ -1,7 +1,7 @@ from django.db import models from django.db.models.expressions import Value from django.db.models.functions import Cast -from django.test import TestCase +from django.test import TestCase, ignore_warnings, skipUnlessDBFeature from .models import Author @@ -19,6 +19,13 @@ class CastTests(TestCase): numbers = Author.objects.annotate(cast_string=Cast('age', models.CharField(max_length=255)),) self.assertEqual(numbers.get().cast_string, '1') + # Silence "Truncated incorrect CHAR(1) value: 'Bob'". + @ignore_warnings(module='django.db.backends.mysql.base') + @skipUnlessDBFeature('supports_cast_with_precision') + def test_cast_to_char_field_with_max_length(self): + names = Author.objects.annotate(cast_string=Cast('name', models.CharField(max_length=1))) + self.assertEqual(names.get().cast_string, 'B') + def test_cast_to_integer(self): for field_class in ( models.IntegerField, -- cgit v1.3