Opened 8 months ago
Closed 8 months ago
#36262 closed Cleanup/optimization (fixed)
GeneratedField.db_persist defaults to None but is required to be set as either True or False
| 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 (last modified by )
Description:
GeneratedField.db_persist attribute is set to db_persist=None, 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
Change History (6)
comment:1 by , 8 months ago
| Description: | modified (diff) |
|---|---|
| Patch needs improvement: | set |
| Summary: | GeneratedField.db_persist has None=True but it's still required to be set and True or False → GeneratedField.db_persist defaults to None but is required to be set as either True or False |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 8 months ago
comment:3 by , 8 months ago
At this point it's not -- there's an owner and a linked PR (see the fields in the ticket metadata).
comment:5 by , 8 months ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
I’d like to work on this. Could you confirm if this is still available?