Opened 3 years ago
Last modified 3 years ago
#33916 closed New feature
default does not work for enums with flags if two or more items are used. — at Version 1
| Reported by: | Willem Van Onsem | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 4.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
If we work with a field:
regex_flags = models.IntegerField(default=re.UNICODE | re.IGNORECASE)
This is turned into a migration with:
default=re.RegexFlag[None]
This is due to the fact that the EnumSerializer aims to work with the .name of the item, but if there is no single item for the given value, then there is no such name.
In that case, we can use enum._decompose to obtain a list of names, and create an expression to create the enum value by "ORing" the items together.
Change History (2)
by , 3 years ago
| Attachment: | enum_serializer.patch added |
|---|
comment:1 by , 3 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
patch of the EnumSerializer