8000 Fixed #32132 -- Fixed column types in m2m intermediary tables for Positive(Big/Small)IntegerFields. by David-Wobrock · Pull Request #13592 · django/django · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed #32132 -- Fixed column types in m2m intermediary tables for Pos…
…itive(Big/Small)IntegerFields.
  • Loading branch information
David-Wobrock authored and felixxm committed Nov 2, 2020
commit cfc7cd6513a72b8c5898c264d04bdf49f897a1de
31 changes: 21 additions & 10 deletions django/db/models/fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,13 @@ def formfield(self, **kwargs):
})


class SmallIntegerField(IntegerField):
description = _('Small integer')

def get_internal_type(self):
return 'SmallIntegerField'


class IPAddressField(Field):
empty_strings_allowed = False
description = _("IPv4 address")
Expand Down Expand Up @@ -2006,6 +2013,17 @@ def get_internal_type(self):


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):
"""
Expand All @@ -2019,10 +2037,10 @@ def rel_db_type(self, connection):
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):
Expand All @@ -2048,7 +2066,7 @@ def formfield(self, **kwargs):
})


class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField):
class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, SmallIntegerField):
description = _("Positive small integer")

def get_internal_type(self):
Expand Down Expand Up @@ -2094,13 +2112,6 @@ def formfield(self, **kwargs):
})


class SmallIntegerField(IntegerField):
description = _("Small integer")

def get_internal_type(self):
return "SmallIntegerField"


class TextField(Field):
description = _("Text")

Expand Down
10 changes: 10 additions & 0 deletions tests/model_fields/test_integerfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -198,6 +203,11 @@ def test_negative_values(self):
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):
Expand Down
0