ephraimbuddy commented on a change in pull request #19367:
URL: https://github.com/apache/airflow/pull/19367#discussion_r754517808



##########
File path: tests/dag_processing/test_processor.py
##########
@@ -481,6 +481,34 @@ def 
test_add_unparseable_zip_file_creates_import_error(self, tmpdir):
             assert import_error.stacktrace == f"invalid syntax 
({TEMP_DAG_FILENAME}, line 1)"
             session.rollback()
 
+    @conf_vars({("core", "dagbag_import_error_tracebacks"): "False"})
+    def test_dag_model_has_import_error_is_true_when_import_error_exists(self, 
tmpdir):
+        dag_file = os.path.join(TEST_DAGS_FOLDER, 
"test_example_bash_operator.py")
+        temp_dagfile = os.path.join(tmpdir, TEMP_DAG_FILENAME)
+        with open(dag_file) as main_dag, open(temp_dagfile, 'w') as next_dag:
+            for line in main_dag:
+                next_dag.write(line)
+        session = settings.Session()
+        # first we parse the dag
+        self._process_file(temp_dagfile, session)
+        # assert DagModel.has_import_errors is false
+        dm = session.query(DagModel).filter(DagModel.fileloc == 
temp_dagfile).first()
+        assert not dm.has_import_errors
+        # corrupt the file
+        with open(temp_dagfile, 'a') as file:
+            file.writelines(UNPARSEABLE_DAG_FILE_CONTENTS)
+
+        self._process_file(temp_dagfile, session)
+        import_errors = session.query(errors.ImportError).all()
+
+        assert len(import_errors) == 1
+        import_error = import_errors[0]
+        assert import_error.filename == temp_dagfile
+        assert import_error.stacktrace == f"invalid syntax 
({TEMP_DAG_FILENAME}, line 53)"

Review comment:
       I think there's no harm in asserting it?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to