Opened 7 years ago
Closed 6 years ago
#29979 closed Cleanup/optimization (fixed)
Refactor AutoField logic into a mixin, implement checks and validators.
| Reported by: | Nick Pope | Owned by: | Nick Pope | 
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev | 
| Severity: | Normal | Keywords: | autofield, validators | 
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
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:
descriptionempty_strings_alloweddefault_error_messagesget_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.
Change History (5)
comment:1 by , 7 years ago
| Has patch: | set | 
|---|
comment:2 by , 7 years ago
| Triage Stage: | Unreviewed → Accepted | 
|---|
Conversation on the PR is already on-going. I’ll provisionally accept this pending an implementation everyone is happy with. 
(Seems reasonable in principle.)
comment:3 by , 7 years ago
| Patch needs improvement: | set | 
|---|
comment:4 by , 6 years ago
| Patch needs improvement: | unset | 
|---|
PR