Opened 8 months ago
Last modified 8 months ago
#36262 closed Cleanup/optimization
GeneratedField.db_persist has None=True but it's still required to be set and True or False — at Initial Version
| Reported by: | Jason Cameron | Owned by: | Jason Cameron |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Jason Cameron | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Description:
GeneratedField.db_persist attribute is set to None=True, which implies that the value can be None. However, just 4 lines lower in the code, it is required to be either True or False. This inconsistency leads a developer to believe that it can be left blank but it cannot.
Steps to Reproduce:
- Create a model using
GeneratedFieldwithdb_persist=Noneordb_persistnot set. - Run the server or execute a command that requires the field validation.
- Observe that the code expects the value to be
TrueorFalsedespite it being set toNone.
Expected Behavior:
The db_persist attribute should consistently accept None throughout the code if it is defined as None=True.
Actual Behavior:
The code expects db_persist to be either True or False and does not handle the None value appropriately.
Would fix https://github.com/typeddjango/django-stubs/pull/2568