Desdroid opened a new issue, #56736:
URL: https://github.com/apache/airflow/issues/56736

   ### Apache Airflow version
   
   3.1.0
   
   ### If "Other Airflow 2/3 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   3.1. changed quite a bit on the SerDe side. Now there is an own SerDe 
implementation for pydantic models. 
   Here: 
https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/serialization/serializers/pydantic.py
   
   The implementation unfortunately doesn't serialize with mode='json'
   See: 
https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_dump
   As an effect, Pydantic models which are more complex and have fields that 
have classes can no longer be JSON serialized, breaking XCOM serialization to 
json.
   
   The fix should be fairly simple though, just adding `mode='json'` to the 
serializer here
   
https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/serialization/serializers/pydantic.py#L49
   should fix this. 
   I haven't been able to set up the airflow repo myself to test it thoug. 
   
   
   Additionally, using pydantic dataclasses is now broken as well, but I will 
create a separate issue for that.  
   
   
   ### What you think should happen instead?
   
   _No response_
   
   ### How to reproduce
   
   Add this dag to your Airflow instance: 
   ```python
   from airflow.sdk import dag, task
   from datetime import datetime, timedelta
   from pydantic import BaseModel, AnyUrl
   
   from pipelines.dags.shared.dag_args import local_tz
   
   
   class UnserializableModel(BaseModel):
       foo: str
       bar: AnyUrl
   
   
   @dag(
       dag_id="pydantic_serde",
       dag_display_name="Pydantic Serialization Errors",
       schedule=timedelta(seconds=30),
       start_date=datetime(2025, 6, 27, 0, 0, 0, tzinfo=local_tz),
       catchup=False,
       description="1.0.0",
   )
   def pydantic_serde() -> None:
       @task
       def return_pydantic_model():
           return UnserializableModel(foo="hello", bar="https://example.com";)
   
       @task
       def consume_pydantic_model(model: UnserializableModel):
           print(model)
   
       consume_pydantic_model(return_pydantic_model())
   
   
   pydantic_serde()
   
   ```
   
   ### Operating System
   
   debian
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### 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]

Reply via email to