Refs #28748 -- Reallowed lazy values in model field choices.
Regression in f9844f4841
.
Thanks Matthias Kestenholz for the report and suggestions.
This commit is contained in:
parent
b002a032f9
commit
3aa9ab39cc
|
@ -245,7 +245,7 @@ class Field(RegisterLookupMixin):
|
|||
return []
|
||||
|
||||
def is_value(value):
|
||||
return isinstance(value, str) or not is_iterable(value)
|
||||
return isinstance(value, (str, Promise)) or not is_iterable(value)
|
||||
|
||||
if is_value(self.choices):
|
||||
return [
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.db import connection, models
|
|||
from django.test import SimpleTestCase, TestCase, skipIfDBFeature
|
||||
from django.test.utils import isolate_apps, override_settings
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
@isolate_apps('invalid_models_tests')
|
||||
|
@ -198,6 +199,12 @@ class CharFieldTests(TestCase):
|
|||
),
|
||||
])
|
||||
|
||||
def test_choices_containing_lazy(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(max_length=10, choices=[['1', _('1')], ['2', _('2')]])
|
||||
|
||||
self.assertEqual(Model._meta.get_field('field').check(), [])
|
||||
|
||||
def test_choices_named_group(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(
|
||||
|
@ -248,6 +255,17 @@ class CharFieldTests(TestCase):
|
|||
),
|
||||
])
|
||||
|
||||
def test_choices_named_group_lazy(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(
|
||||
max_length=10, choices=[
|
||||
[_('knights'), [['L', _('Lancelot')], ['G', _('Galahad')]]],
|
||||
['R', _('Random character')],
|
||||
],
|
||||
)
|
||||
|
||||
self.assertEqual(Model._meta.get_field('field').check(), [])
|
||||
|
||||
def test_bad_db_index_value(self):
|
||||
class Model(models.Model):
|
||||
field = models.CharField(max_length=10, db_index='bad')
|
||||
|
|
Loading…
Reference in New Issue