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

BugFix: Fix writing & deleting Dag Code for Serialized DAGs #8151

Merged
merged 4 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ def sync_to_db(self, owner=None, sync_time=None, session=None):
orm_dag.tags = self.get_dagtags(session=session)

if conf.getboolean('core', 'store_dag_code', fallback=False):
DagCode.bulk_sync_to_db([dag.fileloc for dag in orm_dag])
DagCode.bulk_sync_to_db([orm_dag.fileloc], session=session)

session.commit()

Expand Down
6 changes: 5 additions & 1 deletion tests/models/test_dagcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from airflow.utils.db import create_session
# To move it to a shared module.
from airflow.utils.file import open_maybe_zipped
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_dag_code


Expand All @@ -51,10 +52,11 @@ def _write_two_example_dags(self):
DagCode(xcom_dag.fileloc).sync_to_db()
return [bash_dag, xcom_dag]

@conf_vars({('core', 'store_dag_code'): 'True'})
def _write_example_dags(self):
example_dags = make_example_dags(example_dags_module)
for dag in example_dags.values():
DagCode(dag.fileloc).sync_to_db()
dag.sync_to_db()
return example_dags

def test_sync_to_db(self):
Expand Down Expand Up @@ -98,6 +100,8 @@ def test_detecting_duplicate_key(self, mock_hash):
def _compare_example_dags(self, example_dags):
with create_session() as session:
for dag in example_dags.values():
if dag.is_subdag:
dag.fileloc = dag.parent_dag.fileloc
self.assertTrue(DagCode.has_dag(dag.fileloc))
dag_fileloc_hash = DagCode.dag_fileloc_hash(dag.fileloc)
result = session.query(
Expand Down