Fix issue with coercing valid_values to a tuple
A recent patch exposed valid_values via property, and cocerced the result to a tuple to convey the immutable nature of them. This was a good thought, but unfortunately breaks __repr__ stability, which we use in the fixture to calculate the object hashes. We could make the __repr__ dig into the raw types on the field instead of using the property, but this is probably not the best and smallest change at this point. If we can get everyone to start using tuples for their value_values list, then we could land a change to coerce and enforce that. Right now, we just need to fix the unexpected regression. Change-Id: I09b78e7f816fc26c69a3e9435c9d92d5acb5821b
This commit is contained in:
parent
730659ed6f
commit
f7e5f8e67a
|
@ -293,7 +293,7 @@ class Enum(String):
|
|||
|
||||
@property
|
||||
def valid_values(self):
|
||||
return tuple(self._valid_values)
|
||||
return copy.copy(self._valid_values)
|
||||
|
||||
def coerce(self, obj, attr, value):
|
||||
if value not in self._valid_values:
|
||||
|
|
|
@ -55,7 +55,7 @@ class FakeEnumAlt(fields.Enum):
|
|||
PLATYPUS = "platypus"
|
||||
AARDVARK = "aardvark"
|
||||
|
||||
ALL = (FROG, PLATYPUS, AARDVARK)
|
||||
ALL = set([FROG, PLATYPUS, AARDVARK])
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(FakeEnumAlt, self).__init__(valid_values=FakeEnumAlt.ALL,
|
||||
|
@ -256,6 +256,10 @@ class TestBaseEnum(TestField):
|
|||
self.assertEqual(self.field.valid_values,
|
||||
FakeEnum.ALL)
|
||||
|
||||
def test_valid_values_keeps_type(self):
|
||||
self.assertIsInstance(self.field.valid_values, tuple)
|
||||
self.assertIsInstance(FakeEnumAltField().valid_values, set)
|
||||
|
||||
|
||||
class TestEnum(TestField):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue