Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix behaviour when openlineage raises KeyError (#565)
Make Cosmos more resilient to Openlineage errors. The Openlineage library raises `KeyError` for some community dbt projects (e.g. https://apache-airflow.slack.com/archives/C059CC42E9W/p1695067128727239): ``` [2023-09-18, 19:54:12 UTC] {taskinstance.py:1935} ERROR - Task failed with exception Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 360, in execute self.build_and_run_cmd(context=context) File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 356, in build_and_run_cmd result = self.run_command(cmd=dbt_cmd, env=env, context=context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 230, in run_command self.calculate_openlineage_events_completes(env, Path(tmp_project_dir)) File "/usr/local/lib/python3.11/site-packages/cosmos/operators/local.py", line 278, in calculate_openlineage_events_completes events = openlineage_processor.parse() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openlineage/common/provider/dbt/processor.py", line 211, in parse events += self.parse_test(context, nodes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openlineage/common/provider/dbt/processor.py", line 308, in parse_test assertions = self.parse_assertions(context, nodes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/openlineage/common/provider/dbt/processor.py", line 367, in parse_assertions assertion=test_node["test_metadata"]["name"], ~~~~~~~~~^^^^^^^^^^^^^^^^^ KeyError: 'test_metadata' ``` Closes: #545 Co-authored-by: Javier Hernández Novoa <[email protected]>
- Loading branch information