#34183 closed New feature (wontfix)

Add a ChoicesMeta.max_length property returning the max_length when data type supports len()

Reported by: Coumes Quentin Owned by: Coumes Quentin
Component: Database layer (models, ORM) Version: 4.1
Severity: Normal Keywords: choices, enums
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Coumes Quentin)

It would be helpful for enums inheriting Choices with a data type supporting len() to be able to compute max_length by themselves.

This would make the definition of field's max_length easier as well as automatically create a new migration when deleting/adding members which would change the max_length.

If the data type does not support len(), it could raise TypeError (same exception raise by len) something like :

raise TypeError("Can only compute max_length on data type supporting len()")

I can do the patch if this feature does make sense to you.

Change History (3)

comment:1 by Coumes Quentin, 17 months ago

Owner: changed from nobody to Coumes Quentin
Status: newassigned

comment:2 by Coumes Quentin, 17 months ago

Description: modified (diff)

comment:3 by Mariusz Felisiak, 17 months ago

Component: UtilitiesDatabase layer (models, ORM)
Resolution: wontfix
Status: assignedclosed

Thanks for this ticket, however this would be highly fragile and error prone. First of all, removing an option from choices doesn't guarantee that it will not used by existing rows, so such migrations will quite often crash, or worse, the database may truncate existing data and create values that don't match choices (some database automatically truncate data when precision is changed). Secondly, altering a precision is a locking DDL operation, so it can be really disruptive for users to perform it after each change in choices.

You can start a discussion on DevelopersMailingList, if you don't agree.

Note: See TracTickets for help on using tickets.
Back to Top