The proposal is to move all the auto field "behaviour" into a new
`AutoFieldMixin` and fix `AutoField` and `BigAutoField` to inherit from
this new mixin and `IntegerField` and `BigIntegerField` respectively.
Many attributes and methods would be nicely inherited from the correct
parent field type without requiring redefinition:
- `description`
- `empty_strings_allowed`
- `default_error_messages`
- `get_prep_value()`
- `to_python()`
`AutoField` and `BigAutoField` could also inherit the following checks
from `IntegerField`:
- `IntegerField._check_max_length_warning()`
`AutoField` and `BigAutoField` could also perform minimum and maximum
value validation checks inherited from `IntegerField`.
This should be backwards compatible and potentially will make it easier to
define new types of auto fields based on other fields in the future.
--
Ticket URL: <https://code.djangoproject.com/ticket/29979>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10680 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:1>
* stage: Unreviewed => Accepted
Comment:
Conversation on the PR is already on-going. I’ll provisionally accept this
pending an implementation everyone is happy with.
(Seems reasonable in principle.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:2>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:3>
* needs_better_patch: 1 => 0
Comment:
[https://github.com/django/django/pull/10680 PR] updated. It seems that
this also partially addresses #17337, but that will further depend on #470
for default values for non-integer fields as well as #24042 for replacing
`isinstance(..., AutoField)` checks.
--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"21e559495b8255bba1e8a4429cd083246ab90457" 21e5594]:
{{{
#!CommitTicketReference repository=""
revision="21e559495b8255bba1e8a4429cd083246ab90457"
Fixed #29979, Refs #17337 -- Extracted AutoField field logic into a mixin
and refactored AutoFields.
This reduces duplication by allowing AutoField, BigAutoField and
SmallAutoField to inherit from IntegerField, BigIntegerField and
SmallIntegerField respectively. Doing so also allows for enabling the
max_length warning check and minimum/maximum value validation for auto
fields, as well as providing a mixin that can be used for other possible
future auto field types such as a theoretical UUIDAutoField.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:5>