You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class ReindexStatus(Enum):
ready_to_start = 'ready_to_start'
started = 'started'
class Test(Table):
status = Varchar(choices=ReindexStatus, null=False)
if I do a query like
thing = await Test.objects().first()
I would expect to be able to use the enum class to compare the object field value like:
if thing.status == ReindexStatus.ready_to_start:
However, the field seems to be returned just as a string.
This seems like a bug to me, is it intentional that enum-based fields aren't deserialized back to the enum?
The text was updated successfully, but these errors were encountered:
I agree that converting the values back into enums would be a nice feature. I wonder if it should be a default behaviour, or configurable in some way (maybe via the output clause).
To make the enum comparable to the raw string value you can do this:
# Note - it inherits from `str`classReindexStatus(str, Enum):
ready_to_start='ready_to_start'started='started'
I would argue that it should be the default value, since the object() call is an explicit desire to get the returned object back in a "fully deserialized" form, and Enum casting is part of that. Not sure if it would break for existing users tho.
Given this model:
if I do a query like
I would expect to be able to use the enum class to compare the object field value like:
However, the field seems to be returned just as a string.
This seems like a bug to me, is it intentional that enum-based fields aren't deserialized back to the enum?
The text was updated successfully, but these errors were encountered: