Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix migration when xcom has NaN values#53812

Merged
vatsrahul1001 merged 13 commits intoapache:mainfrom
astronomer:fix-nan-xcom-migration
Sep 3, 2025
Merged

Fix migration when xcom has NaN values#53812
vatsrahul1001 merged 13 commits intoapache:mainfrom
astronomer:fix-nan-xcom-migration

Conversation

Copy link
Contributor

vatsrahul1001 commented Jul 28, 2025 *
edited
Loading

closes: #51178

Testing:

  1. Ran a DAG with 2.11.0, which generates nan value in db [{"day": "2024-06-07", "ArticleCountMetric": NaN}]

from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime


def push_nan_to_xcom(**kwargs):
# This dict contains a NaN, which is not valid JSON
value = [{"day": "2024-06-07", "ArticleCountMetric": float("nan")}]
kwargs["ti"].xcom_push(key="bad_json", value=value)


with DAG(
dag_id="xcom_nan_example",
start_date=datetime(2024, 1, 1),
schedule_interval=None,
catchup=False,
) as dag:
push_nan = PythonOperator(
task_id="push_nan",
python_callable=push_nan_to_xcom,
provide_context=True,
)

  1. Migrated to main now verified migration worked fine with all databases
  1. Verified in db nan is getting converted to string [{"day": "2024-06-07", "ArticleCountMetric": "nan"}]

^ 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.

vatsrahul1001 requested a review from ephraimbuddy as a code owner July 28, 2025 11:54
boring-cyborg bot added area:db-migrations PRs with DB migration kind:documentation labels Jul 28, 2025
Copy link
Member

uranusjr commented Jul 29, 2025

I wonder if it's better to delete those rows instead. XCom is not designed as a long term storage.

Also, what happens if a new ti tries to push invalid values in 3.x?

amoghrajesh assigned vatsrahul1001 Jul 30, 2025
amoghrajesh added this to the Airflow 3.0.4 milestone Jul 30, 2025
eladkal modified the milestones: Airflow 3.0.4, Airflow 3.0.5 Aug 8, 2025
vatsrahul1001 requested a review from amoghrajesh August 13, 2025 08:22
Copy link
Contributor

ephraimbuddy commented Aug 13, 2025

I wonder if it's better to delete those rows instead. XCom is not designed as a long term storage.

Also, what happens if a new ti tries to push invalid values in 3.x?

I prefer this too

Copy link
Contributor Author

vatsrahul1001 commented Aug 13, 2025

I wonder if it's better to delete those rows instead. XCom is not designed as a long term storage.
Also, what happens if a new ti tries to push invalid values in 3.x?

I prefer this too

As per the discussion with @uranusjr, we can serialize nan to string

vatsrahul1001 requested a review from uranusjr August 13, 2025 11:33
amoghrajesh approved these changes Aug 13, 2025
Copy link
Contributor

amoghrajesh left a comment

Choose a reason for hiding this comment

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

@vatsrahul1001 thanks, I think the fix would work as it achieves json compliancy and doesn't change the type too.

vatsrahul1001 added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Aug 13, 2025
kaxil modified the milestones: Airflow 3.0.5, Airflow 3.0.6 Aug 13, 2025
kaxil modified the milestones: Airflow 3.0.6, Airflow 3.0.7 Aug 21, 2025
vatsrahul1001 merged commit dee3a61 into apache:main Sep 3, 2025
59 checks passed
vatsrahul1001 deleted the fix-nan-xcom-migration branch September 3, 2025 11:35
Copy link

github-actions bot commented Sep 3, 2025

Backport failed to create: v3-0-test. View the failure log Run details

Status Branch Result
v3-0-test

You can attempt to backport this manually by running:

cherry_picker dee3a61 v3-0-test

This should apply the commit to the v3-0-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

kaxil modified the milestones: Airflow 3.0.7, Airflow 3.1.0 Sep 13, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Sep 30, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 1, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 2, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 3, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 4, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 5, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 5, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 7, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 8, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 9, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 10, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 11, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 12, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 14, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 15, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 17, 2025
abdulrahman305 bot pushed a commit to qenex-ai/airflow that referenced this pull request Oct 19, 2025
amoghrajesh pushed a commit that referenced this pull request Nov 5, 2025
Fix migration when xcom has NaN values (#53812)

(cherry picked from commit dee3a61)
meldiner pushed a commit to faros-ai/airflow that referenced this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

amoghrajesh amoghrajesh approved these changes

ephraimbuddy Awaiting requested review from ephraimbuddy ephraimbuddy is a code owner

uranusjr Awaiting requested review from uranusjr

Labels

area:db-migrations PRs with DB migration backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch kind:documentation

Projects

None yet

Milestone

Airflow 3.1.0

Development

Successfully merging this pull request may close these issues.

Migration fails on XCom table due to invalid JSONB conversion with NaN values

6 participants