Dev-iL commented on code in PR #37545:
URL: https://github.com/apache/airflow/pull/37545#discussion_r1496363904


##########
airflow/utils/orm_event_handlers.py:
##########
@@ -23,18 +23,25 @@
 import traceback
 
 import sqlalchemy.orm.mapper
-from sqlalchemy import event, exc
+from sqlalchemy import __version__ as sqlalchemy_version, event, exc
 
 from airflow.configuration import conf
 
 log = logging.getLogger(__name__)
 
+SQL_ALCHEMY_V1 = sqlalchemy_version.startswith("1")
+
 
 def setup_event_handlers(engine):
     """Setups event handlers."""
     from airflow.models import import_all_models
 
-    event.listen(sqlalchemy.orm.mapper, "before_configured", 
import_all_models, once=True)
+    event.listen(
+        sqlalchemy.orm.mapper if SQL_ALCHEMY_V1 else sqlalchemy.orm.Mapper,

Review Comment:
   I did include the first of them. Can you suggest a suitable "general" place 
for them? Should I add another file to the utils folder?
   
   It's not exactly a one-liner since it comes with a bunch of imports.
   
   I did not compare `distribution` with `version`, mainly because the latter 
seemed to do what I need.
   
   Re `importlib` - it seems to me that the verbose version is for py<3.8 
(`importlib_metadata` is a backport). I didn't understand @Taragolis' 
[explanation](https://github.com/apache/airflow/pull/37545#discussion_r1494959852)
 why this is not the case.



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