Fixed #32132 -- Fixed column types in m2m intermediary tables for Positive(Big/Small)IntegerFields.

This commit is contained in:
David-Wobrock 2020-10-23 23:56:12 +02:00 committed by Mariusz Felisiak
parent 4ebd633350
commit cfc7cd6513
2 changed files with 31 additions and 10 deletions

View File

@ -1864,6 +1864,13 @@ class BigIntegerField(IntegerField):
})
class SmallIntegerField(IntegerField):
description = _('Small integer')
def get_internal_type(self):
return 'SmallIntegerField'
class IPAddressField(Field):
empty_strings_allowed = False
description = _("IPv4 address")
@ -2006,6 +2013,17 @@ class NullBooleanField(BooleanField):
class PositiveIntegerRelDbTypeMixin:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
if not hasattr(cls, 'integer_field_class'):
cls.integer_field_class = next(
(
parent
for parent in cls.__mro__[1:]
if issubclass(parent, IntegerField)
),
None,
)
def rel_db_type(self, connection):
"""
@ -2019,10 +2037,10 @@ class PositiveIntegerRelDbTypeMixin:
if connection.features.related_fields_match_type:
return self.db_type(connection)
else:
return IntegerField().db_type(connection=connection)
return self.integer_field_class().db_type(connection=connection)
class PositiveBigIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField):
class PositiveBigIntegerField(PositiveIntegerRelDbTypeMixin, BigIntegerField):
description = _('Positive big integer')
def get_internal_type(self):
@ -2048,7 +2066,7 @@ class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField):
})
class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField):
class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, SmallIntegerField):
description = _("Positive small integer")
def get_internal_type(self):
@ -2094,13 +2112,6 @@ class SlugField(CharField):
})
class SmallIntegerField(IntegerField):
description = _("Small integer")
def get_internal_type(self):
return "SmallIntegerField"
class TextField(Field):
description = _("Text")

View File

@ -176,6 +176,11 @@ class BigIntegerFieldTests(IntegerFieldTests):
class PositiveSmallIntegerFieldTests(IntegerFieldTests):
model = PositiveSmallIntegerModel
documented_range = (0, 32767)
rel_db_type_class = (
models.PositiveSmallIntegerField
if connection.features.related_fields_match_type
else models.SmallIntegerField
)
class PositiveIntegerFieldTests(IntegerFieldTests):
@ -198,6 +203,11 @@ class PositiveIntegerFieldTests(IntegerFieldTests):
class PositiveBigIntegerFieldTests(IntegerFieldTests):
model = PositiveBigIntegerModel
documented_range = (0, 9223372036854775807)
rel_db_type_class = (
models.PositiveBigIntegerField
if connection.features.related_fields_match_type
else models.BigIntegerField
)
class ValidationTests(SimpleTestCase):