Taragolis commented on code in PR #37545:
URL: https://github.com/apache/airflow/pull/37545#discussion_r1494644533


##########
tests/utils/test_orm_event_handlers.py:
##########
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""These tests ensure compatibility with the deprecation of 
`sqlalchemy.orm.mapper()` in SQLAlchemy 2.0.0.b1.
+See also: 
https://docs.sqlalchemy.org/en/21/orm/mapping_styles.html#orm-imperative-mapping
+"""
+from __future__ import annotations
+
+import warnings
+
+import pytest
+from sqlalchemy.exc import InvalidRequestError, SADeprecationWarning
+
+from airflow.utils.orm_event_handlers import setup_event_handlers
+
+
+def test_setup_event_handlers_no_warnings():
+    with warnings.catch_warnings(record=True) as warning_list:
+        try:
+            setup_event_handlers(engine=None)
+        except InvalidRequestError:
+            # We are only interested in the warning that may be issued at the 
beginning of the method.
+            pass

Review Comment:
   You could just setup to catch this kind of warnings and raise an error
   
   ```suggestion
           warnings.simplefilter("error", category=SADeprecationWarning)
           try:
               setup_event_handlers(engine=None)
           except InvalidRequestError:
               # We are only interested in the warning that may be issued at 
the beginning of the method.
               pass
   ```



##########
tests/utils/test_orm_event_handlers.py:
##########
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""These tests ensure compatibility with the deprecation of 
`sqlalchemy.orm.mapper()` in SQLAlchemy 2.0.0.b1.
+See also: 
https://docs.sqlalchemy.org/en/21/orm/mapping_styles.html#orm-imperative-mapping
+"""
+from __future__ import annotations
+
+import warnings
+
+import pytest
+from sqlalchemy.exc import InvalidRequestError, SADeprecationWarning
+
+from airflow.utils.orm_event_handlers import setup_event_handlers
+
+
+def test_setup_event_handlers_no_warnings():
+    with warnings.catch_warnings(record=True) as warning_list:
+        try:
+            setup_event_handlers(engine=None)
+        except InvalidRequestError:
+            # We are only interested in the warning that may be issued at the 
beginning of the method.
+            pass
+
+        # Filter out SADeprecationWarning from the warning list
+        sa_deprecation_warnings = [
+            warning for warning in warning_list if 
issubclass(warning.category, SADeprecationWarning)
+        ]
+
+        # Assert that no SADeprecationWarning was captured
+        assert (
+            len(sa_deprecation_warnings) == 0
+        ), f"Expected no SADeprecationWarning, but got 
{len(sa_deprecation_warnings)} warnings."

Review Comment:
   If you setup warnings filter, then you do not need this code
   
   
   ```suggestion
   ```



##########
airflow/settings.py:
##########
@@ -27,7 +27,7 @@
 from typing import TYPE_CHECKING, Any, Callable
 
 import pluggy
-from sqlalchemy import create_engine, exc, text
+from sqlalchemy import __version__ as sqlalchemy_version, create_engine, exc, 
text

Review Comment:
   We don't have a discussion yet about whether or not we should use 
`__version__` or `importlib.metadata`.
   @potiuk any thoughts? I'm personally have no objections to use it for now, 
because SQLachemy maintainers do not announced about deprecate/remove 
`__version__`



##########
tests/utils/test_orm_event_handlers.py:
##########
@@ -0,0 +1,51 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""These tests ensure compatibility with the deprecation of 
`sqlalchemy.orm.mapper()` in SQLAlchemy 2.0.0.b1.
+See also: 
https://docs.sqlalchemy.org/en/21/orm/mapping_styles.html#orm-imperative-mapping
+"""
+from __future__ import annotations
+
+import warnings
+
+import pytest
+from sqlalchemy.exc import InvalidRequestError, SADeprecationWarning
+
+from airflow.utils.orm_event_handlers import setup_event_handlers
+
+
+def test_setup_event_handlers_no_warnings():
+    with warnings.catch_warnings(record=True) as warning_list:
+        try:
+            setup_event_handlers(engine=None)
+        except InvalidRequestError:
+            # We are only interested in the warning that may be issued at the 
beginning of the method.
+            pass
+
+        # Filter out SADeprecationWarning from the warning list
+        sa_deprecation_warnings = [
+            warning for warning in warning_list if 
issubclass(warning.category, SADeprecationWarning)
+        ]
+
+        # Assert that no SADeprecationWarning was captured
+        assert (
+            len(sa_deprecation_warnings) == 0
+        ), f"Expected no SADeprecationWarning, but got 
{len(sa_deprecation_warnings)} warnings."
+
+
+if __name__ == "__main__":
+    pytest.main([__file__])

Review Comment:
   ```suggestion
   ```



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to