Opened 2 years ago

Closed 2 years ago

#33916 closed New feature (fixed)

Support for serialization of combination of Enum flags.

Reported by: Willem Van Onsem Owned by: Willem Van Onsem
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 Willem Van Onsem)

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.

Attachments (1)

enum_serializer.patch (1.3 KB ) - added by Willem Van Onsem 2 years ago.
patch of the EnumSerializer

Download all attachments as: .zip

Change History (8)

by Willem Van Onsem, 2 years ago

Attachment: enum_serializer.patch added

patch of the EnumSerializer

comment:1 by Willem Van Onsem, 2 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 2 years ago

Owner: changed from nobody to Willem Van Onsem
Status: newassigned
Summary: default does not work for enums with flags if two or more items are used.Support for serialization of combination of Enum flags.
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 by Mariusz Felisiak, 2 years ago

Type: BugNew feature

Support for enum.Flag has never been documented.

comment:4 by Mariusz Felisiak, 2 years ago

Needs documentation: set
Patch needs improvement: set

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 08688bd7:

Refs #33916 -- Added tests for serialization of enum.Flag in migrations.

comment:6 by Mariusz Felisiak, 2 years ago

Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 16fffc8:

Fixed #33916 -- Added support for serialization of enum.Flag in migrations.

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