Refs #23801 -- Made integer field max_length warning show correct field type.
This commit is contained in:
parent
856ba1ec86
commit
c512912463
|
@ -1773,7 +1773,7 @@ class IntegerField(Field):
|
|||
if self.max_length is not None:
|
||||
return [
|
||||
checks.Warning(
|
||||
"'max_length' is ignored when used with IntegerField",
|
||||
"'max_length' is ignored when used with %s." % self.__class__.__name__,
|
||||
hint="Remove 'max_length' from field",
|
||||
obj=self,
|
||||
id='fields.W122',
|
||||
|
|
|
@ -143,7 +143,8 @@ Model fields
|
|||
appeared before support for null values was added in Django 2.1.*
|
||||
* **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
|
||||
* **fields.E121**: ``max_length`` must be a positive integer.
|
||||
* **fields.W122**: ``max_length`` is ignored when used with ``IntegerField``.
|
||||
* **fields.W122**: ``max_length`` is ignored when used with
|
||||
``<integer field type>``.
|
||||
* **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
|
||||
* **fields.E131**: ``decimal_places`` must be a non-negative integer.
|
||||
* **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
|
||||
|
|
|
@ -617,17 +617,24 @@ class IntegerFieldTests(SimpleTestCase):
|
|||
|
||||
def test_max_length_warning(self):
|
||||
class Model(models.Model):
|
||||
value = models.IntegerField(max_length=2)
|
||||
integer = models.IntegerField(max_length=2)
|
||||
biginteger = models.BigIntegerField(max_length=2)
|
||||
smallinteger = models.SmallIntegerField(max_length=2)
|
||||
positiveinteger = models.PositiveIntegerField(max_length=2)
|
||||
positivesmallinteger = models.PositiveSmallIntegerField(max_length=2)
|
||||
|
||||
field = Model._meta.get_field('value')
|
||||
self.assertEqual(field.check(), [
|
||||
DjangoWarning(
|
||||
"'max_length' is ignored when used with IntegerField",
|
||||
hint="Remove 'max_length' from field",
|
||||
obj=field,
|
||||
id='fields.W122',
|
||||
)
|
||||
])
|
||||
for field in Model._meta.get_fields():
|
||||
if field.auto_created:
|
||||
continue
|
||||
with self.subTest(name=field.name):
|
||||
self.assertEqual(field.check(), [
|
||||
DjangoWarning(
|
||||
"'max_length' is ignored when used with %s." % field.__class__.__name__,
|
||||
hint="Remove 'max_length' from field",
|
||||
obj=field,
|
||||
id='fields.W122',
|
||||
)
|
||||
])
|
||||
|
||||
|
||||
@isolate_apps('invalid_models_tests')
|
||||
|
|
Loading…
Reference in New Issue