Skip to content

Conversation

@Desdroid
Copy link
Contributor

Ensure that pydantic dataclasses are not detected as pydantic models.

As discussed in #56739 check more strictly for pydantic models and avoid detecting pydantic dataclasses as pydantic models.
Went with the suggestion of @amoghrajesh and used stdlib dataclasses to check that the detected model is not a dataclass.

Fixes: #56739


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@boring-cyborg
Copy link

boring-cyborg bot commented Oct 17, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@Desdroid Desdroid force-pushed the bugfix/#56739-pydantic-dataclass-serialization branch 2 times, most recently from 09b4dac to 1fbf590 Compare October 17, 2025 10:03
Copy link
Contributor

@sjyangkevin sjyangkevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Desdroid thanks for the PR. The change looks good to me.

While testing the change; I noticed to deserialize this pydantic dataclass, we do need to whitelist it, I hope it is something we also need to do before. The current implementation ensure to deserialize only known objects, due to security considerations.

Screenshot from 2025-10-17 20-31-10

To whitelist it, we can configure the following airflow config, below is an example.

Screenshot from 2025-10-17 20-31-28

@Desdroid
Copy link
Contributor Author

I am not sure I understand you.
This PR does not change the need to whitelist custom classes that one wants to serialize / deserialize.
One still needs to add them or the package to the whitelist - that's also what we do in our setup.
Do I also need to change stuff in the default breeze setup?

@Desdroid Desdroid force-pushed the bugfix/#56739-pydantic-dataclass-serialization branch from 1fbf590 to 5a8a275 Compare October 23, 2025 12:07
@Desdroid
Copy link
Contributor Author

@sjyangkevin So can you tell me what else is required? CI test are good.

@sjyangkevin
Copy link
Contributor

@sjyangkevin So can you tell me what else is required? CI test are good.

It looks good to me. Would be great to have a second eyes on it @amoghrajesh , @bolkedebruin

@amoghrajesh amoghrajesh self-requested a review October 24, 2025 07:13
Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @Desdroid!
Some nits, otherwise looks good.

@Desdroid Desdroid force-pushed the bugfix/#56739-pydantic-dataclass-serialization branch from 487fa59 to 5331042 Compare October 27, 2025 10:32
@amoghrajesh
Copy link
Contributor

Just rebased it to fix the CI

@amoghrajesh
Copy link
Contributor

@uranusjr can you take another look at this one?

@Desdroid Desdroid force-pushed the bugfix/#56739-pydantic-dataclass-serialization branch from d14e69f to 7cf8a77 Compare October 31, 2025 09:53
@Desdroid
Copy link
Contributor Author

@bolkedebruin Alright, moved it back up then.

Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolkedebruin bolkedebruin merged commit 9613558 into apache:main Oct 31, 2025
62 checks passed
amoghrajesh pushed a commit to amoghrajesh/airflow that referenced this pull request Oct 31, 2025
* Check more strictly for pydantic models. Ensure that pydantic dataclasses are not detected as pydantic models. (apache#56739)

* Move test to other file. (apache#56739)
(cherry picked from commit 9613558)

Co-authored-by: Desdroid <Desdroid@users.noreply.github.com>
@amoghrajesh
Copy link
Contributor

@Desdroid Desdroid deleted the bugfix/#56739-pydantic-dataclass-serialization branch October 31, 2025 12:29
amoghrajesh added a commit that referenced this pull request Oct 31, 2025
…57616)

* Check more strictly for pydantic models. Ensure that pydantic dataclasses are not detected as pydantic models. (#56739)

* Move test to other file. (#56739)
(cherry picked from commit 9613558)

Co-authored-by: Desdroid <Desdroid@users.noreply.github.com>
Copilot AI pushed a commit to jason810496/airflow that referenced this pull request Dec 5, 2025
* Check more strictly for pydantic models. Ensure that pydantic dataclasses are not detected as pydantic models. (apache#56739)

* Move test to other file. (apache#56739)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SerDe: XCOM Serialization of Pydantic Dataclasses Broken

5 participants