diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py
index 38da1e6ecc..295afbfebf 100644
a
|
b
|
class EnumSerializer(BaseSerializer):
|
125 | 125 | def serialize(self): |
126 | 126 | enum_class = self.value.__class__ |
127 | 127 | module = enum_class.__module__ |
| 128 | if issubclass(enum_class, enum.Flag): |
| 129 | members, __ = enum._decompose(enum_class, self.value) |
| 130 | else: |
| 131 | members = (self.value,) |
128 | 132 | return ( |
129 | | "%s.%s[%r]" % (module, enum_class.__qualname__, self.value.name), |
| 133 | " | ".join(f"{module}.{enum_class.__qualname__}[{item.name!r}]" for item in members), |
130 | 134 | {"import %s" % module}, |
131 | 135 | ) |
132 | 136 | |
… |
… |
class FunctionTypeSerializer(BaseSerializer):
|
154 | 158 | "import %s" % module |
155 | 159 | } |
156 | 160 | # Further error checking |
157 | | if self.value.__name__ == "<lambda>": |
| 161 | # use .co_name, since this can not be modified, whereas __name__ can be altered |
| 162 | # https://stackoverflow.com/a/56451124/67579 |
| 163 | if self.value.__code__.co_name == "<lambda>": |
158 | 164 | raise ValueError("Cannot serialize function: lambda") |
159 | 165 | if self.value.__module__ is None: |
160 | 166 | raise ValueError("Cannot serialize function %r: No module" % self.value) |