Opened 2 years ago
Last modified 2 years ago
#33916 closed New feature
default does not work for enums with flags if two or more items are used. — at Initial Version
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
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.
patch of the EnumSerializer