[Django] #29979: Refactor AutoField logic into a mixin, implement checks and validators.

9 views
Skip to first unread message

Django

unread,
Nov 22, 2018, 4:04:10 PM11/22/18
to django-...@googlegroups.com
#29979: Refactor AutoField logic into a mixin, implement checks and validators.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) | Keywords: autofield,
Severity: Normal | validators
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently `AutoField` inherits from `Field` and `BigAutoField` from
`AutoField`. In effect they largely redefine `IntegerField` and
`BigIntegerField` respectively, but add in the auto field "behaviour". As
a result they do not perform some of the system checks, e.g. `max_length`
warning, nor the validation checks, e.g. range checks, that the integer
fields do.

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.

Django

unread,
Nov 22, 2018, 4:14:26 PM11/22/18
to django-...@googlegroups.com
#29979: Refactor AutoField logic into a mixin, implement checks and validators.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: autofield, | Triage Stage:
validators | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/10680 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:1>

Django

unread,
Nov 23, 2018, 6:10:48 AM11/23/18
to django-...@googlegroups.com
#29979: Refactor AutoField logic into a mixin, implement checks and validators.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: autofield, | Triage Stage: Accepted
validators |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* 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>

Django

unread,
Nov 27, 2018, 10:40:42 AM11/27/18
to django-...@googlegroups.com
#29979: Refactor AutoField logic into a mixin, implement checks and validators.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: autofield, | Triage Stage: Accepted
validators |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29979#comment:3>

Django

unread,
Jul 26, 2019, 7:15:52 PM7/26/19
to django-...@googlegroups.com
#29979: Refactor AutoField logic into a mixin, implement checks and validators.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: autofield, | Triage Stage: Accepted
validators |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* 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>

Django

unread,
Aug 20, 2019, 4:37:06 AM8/20/19
to django-...@googlegroups.com
#29979: Refactor AutoField logic into a mixin, implement checks and validators.
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: autofield, | Triage Stage: Accepted
validators |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages