mixilchenko opened a new issue, #51016:
URL: https://github.com/apache/airflow/issues/51016
### Apache Airflow version
main (development)
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
When enumeration inherits some primitive type (e.g. str, int),
deserialization makes the value primitive as well.
```python
import enum
from airflow.serialization.serde import deserialize, serialize
class MyEnum(enum.IntEnum):
A = 1
B = 2
value = MyEnum.A
res = deserialize(serialize(value))
assert res is MyEnum.A, f'{type(res)=}, {res=}'
# AssertionError: type(res)=<class 'int'>, res=1
```
### What you think should happen instead?
This is little unexpected for me as a user and for mypy
```python
@task
def my_task(v: MyEnum):
assert is instance(v, MyEnum), 'fine for mypy, fails in runtime'
v = MyEnum(v)
...
my_task(MyEnum.A)
```
The other issue is that if I add airflow compatible custom serialization the
result is incorrect too
```python
class MyEnum(enum.IntEnum):
A = 1
B = 2
def serialize(self):
return f'{self.name}.{self.value}'
res = serialize(MyEnum.A)
assert res == 'A.1', f'{type(res)=}, {res=}'
# AssertionError: type(res)=<class 'int'>, res=1
```
I would expect one of
- implement default serialization and deserialization for enums
- fail with `TypeError: cannot serialize object of type <enumeration
'MyEnum'>` unless it implements the interface and is registered for
deserialization (as it happens for enums that do not inherit primitive)
### How to reproduce
See the snippet above
### Operating System
Debian GNU/Linux 12 (bookworm)
### Versions of Apache Airflow Providers
_No response_
### Deployment
Virtualenv installation
### Deployment details
_No response_
### Anything else?
_No response_
### Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]