Skip to content

Conversation

UnknownPlatypus
Copy link
Contributor

I went for a tiny wrapper on top of SmallIntegerField, its convenient because we want the same implementation for a lot of hooks (db_check, cast_db_type, db_type_suffix) but currently, the validators hook is a bit incorrect because it uses SmallIntegerField ranges (-32768, 32767) instead of (-128, 127).

The ranges are stored on connection.ops.integer_field_range which makes them a bit difficult to change.
My only working idea for now would be to override validators with mostly the IntegerField.validators hook implementation, just altering the min/max values but it's not very clean and might drift.

Do you have a recommendation on how to solve this ?

Fixes #1121

@adamchainz
Copy link
Owner

The ranges are stored on connection.ops.integer_field_range which makes them a bit difficult to change. My only working idea for now would be to override validators with mostly the IntegerField.validators hook implementation, just altering the min/max values but it's not very clean and might drift.

Do you have a recommendation on how to solve this ?

I looked a bit more at Django’s source and found Field.default_validators can be used to fix this. I just pushed a commit doing so.

@adamchainz adamchainz force-pushed the add-tiny-integer-field branch from ff777b1 to a1180f7 Compare May 13, 2025 21:13
…tly covered by MySQL docs and a necesseity before any field data type change
@adamchainz adamchainz merged commit f53978a into adamchainz:main May 13, 2025
34 checks passed
@adamchainz adamchainz changed the title Add tiny integer field Add tiny integer fields May 13, 2025
@adamchainz
Copy link
Owner

Thanks for this! I did a bunch of small cleanup, which you might want to check the commits for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TinyIntegerField and PositiveTinyIntegerField
2 participants