Skip to content

Commit b220b6c

Browse files
committed
add warning about auto to usage doc, fix CI
1 parent 27c94f6 commit b220b6c

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

django_enum/tests/tests.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1262,24 +1262,24 @@ def test_drf_serializer(self):
12621262

12631263
class TestSerializer(serializers.ModelSerializer):
12641264

1265-
small_pos_int = EnumField(SmallPosIntEnum)
1266-
small_int = EnumField(SmallIntEnum)
1267-
pos_int = EnumField(PosIntEnum)
1268-
int = EnumField(IntEnum)
1269-
big_pos_int = EnumField(BigPosIntEnum)
1270-
big_int = EnumField(BigIntEnum)
1271-
constant = EnumField(Constants)
1272-
text = EnumField(TextEnum)
1273-
extern = EnumField(ExternEnum)
1274-
dj_int_enum = EnumField(DJIntEnum)
1275-
dj_text_enum = EnumField(DJTextEnum)
1276-
non_strict_int = EnumField(SmallPosIntEnum, strict=False)
1265+
small_pos_int = EnumField(self.SmallPosIntEnum)
1266+
small_int = EnumField(self.SmallIntEnum)
1267+
pos_int = EnumField(self.PosIntEnum)
1268+
int = EnumField(self.IntEnum)
1269+
big_pos_int = EnumField(self.BigPosIntEnum)
1270+
big_int = EnumField(self.BigIntEnum)
1271+
constant = EnumField(self.Constants)
1272+
text = EnumField(self.TextEnum)
1273+
extern = EnumField(self.ExternEnum)
1274+
dj_int_enum = EnumField(self.DJIntEnum)
1275+
dj_text_enum = EnumField(self.DJTextEnum)
1276+
non_strict_int = EnumField(self.SmallPosIntEnum, strict=False)
12771277
non_strict_text = EnumField(
1278-
TextEnum,
1278+
self.TextEnum,
12791279
strict=False,
12801280
allow_blank=True
12811281
)
1282-
no_coerce = EnumField(SmallPosIntEnum)
1282+
no_coerce = EnumField(self.SmallPosIntEnum)
12831283

12841284
class Meta:
12851285
model = EnumTester

doc/source/usage.rst

+19-6
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ simple declarative syntax are possible with ``EnumField``. See
6969
External Enum Types
7070
###################
7171

72-
Externally defined, that is ``Enum`` classes defined externally to your code
73-
base or enum classes that otherwise do not inherit from Django's Choices type,
74-
are supported. When no choices are present on an ``Enum`` type, ``EnumField``
75-
will attempt to use the ``label`` member on each enumeration value if it is
76-
present, otherwise the labels will be based off the enumeration name. Choices
77-
can also be overridden at the ``EnumField`` declaration.
72+
``Enum`` classes defined externally to your code base or enum classes that
73+
otherwise do not inherit from Django's ``Choices`` type, are supported. When no
74+
choices are present on an ``Enum`` type, ``EnumField`` will attempt to use the
75+
``label`` member on each enumeration value if it is present, otherwise the
76+
labels will be based off the enumeration name. Choices can also be overridden
77+
at the ``EnumField`` declaration.
78+
79+
In short, ``EnumField`` should work with any subclass of ``Enum``.
7880

7981
.. code:: python
8082
@@ -94,6 +96,17 @@ can also be overridden at the ``EnumField`` declaration.
9496
9597
The above code will produce a choices set like ``[('V0', 'VALUE0'), ...]``.
9698
99+
.. warning::
100+
101+
One nice feature of Django's ``Choices`` type is that it disables
102+
``auto()`` on ``Enum`` fields. ``auto()`` can be dangerous because the
103+
values assigned depend on the order of declaration. This means that if the
104+
order changes existing database values will no longer align with the
105+
enumeration values. When using ``Enums`` where control over the values is
106+
not certain it is a good idea to add integration tests that look for value
107+
changes.
108+
109+
97110
Parameters
98111
##########
99112

0 commit comments

Comments
 (0)