uranusjr commented on code in PR #42913:
URL: https://github.com/apache/airflow/pull/42913#discussion_r1825421855


##########
airflow/models/dagcode.py:
##########
@@ -196,14 +159,25 @@ def code(cls, fileloc, session: Session = NEW_SESSION) -> 
str:
 
     @staticmethod
     def _get_code_from_file(fileloc):
-        with open_maybe_zipped(fileloc, "r") as f:
-            code = f.read()
-        return code
+        try:
+            with open_maybe_zipped(fileloc, "r") as f:
+                code = f.read()
+            return code
+        except FileNotFoundError:
+            test_mode = conf.get("core", "unit_test_mode")
+            if test_mode:
+                return "source_code"
+            raise
 
     @classmethod
     @provide_session
     def _get_code_from_db(cls, fileloc, session: Session = NEW_SESSION) -> str:
-        dag_code = session.scalar(select(cls).where(cls.fileloc_hash == 
cls.dag_fileloc_hash(fileloc)))
+        dag_code = session.scalar(
+            select(cls)
+            .where(cls.fileloc_hash == cls.dag_fileloc_hash(fileloc))
+            .order_by(cls.last_updated.desc())

Review Comment:
   Is is possible for this to find more than one row? `fileloc_hash` is the 
primary key.



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