Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XCom.delete error in Airflow 2.2.0 #18956

Merged
merged 1 commit into from
Oct 14, 2021

Conversation

jordanjeremy
Copy link
Contributor

In Airflow 2.2.0 XCom.delete causes error, by trying to update dag_run table dag_id and execution_date columns to NULLs.

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "dag_id" violates not-null constraint
[SQL: UPDATE dag_run SET dag_id=%(dag_id)s, execution_date=%(execution_date)s WHERE dag_run.id = %(dag_run_id)s]
[parameters: {'dag_id': None, 'execution_date': None, 'dag_run_id': 2409}]

Setting passive_deletes to the string value 'all' will disable the "nulling out" behavior.

In Airflow 2.2.0 XCom.delete causes error, by trying to update dag_run table dag_id and execution_date columns to NULLs.

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "dag_id" violates not-null constraint
[SQL: UPDATE dag_run SET dag_id=%(dag_id)s, execution_date=%(execution_date)s WHERE dag_run.id = %(dag_run_id)s]
[parameters: {'dag_id': None, 'execution_date': None, 'dag_run_id': 2409}]

Setting passive_deletes to the string value ‘all’ will disable the “nulling out”
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 13, 2021

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 Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, mypy and type annotations). Our pre-commits 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.
    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

@kaxil kaxil requested a review from uranusjr October 13, 2021 19:01
@uranusjr uranusjr added this to the Airflow 2.2.1 milestone Oct 13, 2021
@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Oct 13, 2021
@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@potiuk potiuk merged commit 47c5973 into apache:main Oct 14, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Oct 14, 2021

Awesome work, congrats on your first merged pull request!

@potiuk
Copy link
Member

potiuk commented Oct 14, 2021

One doubt that came to me afer merging. Should we have a migration updated after that change @uranusjr @jordanjeremy ?

@jordanjeremy
Copy link
Contributor Author

@potiuk I do not believe that any migration changes are required. In the Airflow 2.2.0 update changes were made to add a foreign key between the task_instance and dag_run tables. As part of that the dag_run table columns for dag_id and execution_date had the not null constraint added (e6c56c4).

This change doesn't really change the relationship between the xcom and dag_run tables. It is changing what sqlalchemy tries to do when an xcom is deleted. From the sqlalchemy documentation, the default behavior:
Normally, when a parent item is deleted, all child items are loaded so that they can either be marked as deleted, or have their foreign key to the parent set to NULL

So when deleting the xcom, sqlalchemy tried to set the dag_id and execution_date in the dag_run table to null, which is when the error happened due to the recently added not null constraint.

The change in this request stops sqlalchemy from trying to also update the dag_run table when deleting an xcom record.
setting the flag to the string value ‘all’ will disable the “nulling out” of the child foreign keys

@uranusjr
Copy link
Member

Correct, the relationship behaviour is handled entirely in Python and stores nothing in the database.

@potiuk
Copy link
Member

potiuk commented Oct 14, 2021

Cool! Great to confirm that - I thought so, but I was not entirely sure :)

jedcunningham pushed a commit that referenced this pull request Oct 14, 2021
In Airflow 2.2.0 XCom.delete causes error, by trying to update dag_run table dag_id and execution_date columns to NULLs.

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "dag_id" violates not-null constraint
[SQL: UPDATE dag_run SET dag_id=%(dag_id)s, execution_date=%(execution_date)s WHERE dag_run.id = %(dag_run_id)s]
[parameters: {'dag_id': None, 'execution_date': None, 'dag_run_id': 2409}]

Setting passive_deletes to the string value ‘all’ will disable the “nulling out”

(cherry picked from commit 47c5973)
jedcunningham pushed a commit to astronomer/airflow that referenced this pull request Oct 26, 2021
In Airflow 2.2.0 XCom.delete causes error, by trying to update dag_run table dag_id and execution_date columns to NULLs.

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "dag_id" violates not-null constraint
[SQL: UPDATE dag_run SET dag_id=%(dag_id)s, execution_date=%(execution_date)s WHERE dag_run.id = %(dag_run_id)s]
[parameters: {'dag_id': None, 'execution_date': None, 'dag_run_id': 2409}]

Setting passive_deletes to the string value ‘all’ will disable the “nulling out”

(cherry picked from commit 47c5973)
jedcunningham pushed a commit to astronomer/airflow that referenced this pull request Oct 27, 2021
In Airflow 2.2.0 XCom.delete causes error, by trying to update dag_run table dag_id and execution_date columns to NULLs.

sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column "dag_id" violates not-null constraint
[SQL: UPDATE dag_run SET dag_id=%(dag_id)s, execution_date=%(execution_date)s WHERE dag_run.id = %(dag_run_id)s]
[parameters: {'dag_id': None, 'execution_date': None, 'dag_run_id': 2409}]

Setting passive_deletes to the string value ‘all’ will disable the “nulling out”

(cherry picked from commit 47c5973)
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full tests needed We need to run full set of tests for this PR to merge type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants