45461 remove remaining session query usages#62758
45461 remove remaining session query usages#62758kunaljubce wants to merge 8 commits intoapache:mainfrom
Conversation
| mock_session.delete.assert_called_once_with(mock_deadline) | ||
| else: | ||
| mock_session.query.assert_not_called() | ||
| mock_session.execute.assert_not_called() |
There was a problem hiding this comment.
Change done to align with https://github.com/kunaljubce/airflow/blob/main/airflow-core/src/airflow/models/deadline.py#L179
| session = Mock() | ||
| assert SkipMixin().skip(dag_run=None, execution_date=None, tasks=[]) is None | ||
| assert not session.query.called | ||
| assert not session.scalars.called |
There was a problem hiding this comment.
Change done to align with https://github.com/apache/airflow/blob/v2-11-stable/airflow/models/skipmixin.py#L149
|
Thanks @kunaljubce !! Good catch !! Will work on this prek hooks again to see what we can do to catch this types of patterns ! |
| try: | ||
| from airflow.sdk import timezone | ||
| except ImportError: # Fallback for Airflow < 3.1 | ||
| from airflow.utils import timezone # type: ignore[attr-defined,no-redef] |
There was a problem hiding this comment.
Import from from airflow.providers.common.compat.sdk instead
There was a problem hiding this comment.
@uranusjr Done! Out of curiosity, is this change only to conform to a particular standard for imports? If that's the case, should we also do the same change in other places, e.g. https://github.com/kunaljubce/airflow/blob/main/airflow-core/tests/unit/models/test_deadline.py#L33
| # Module map: module_name -> module_path(s) | ||
| # For entire modules that have been moved (e.g., timezone) | ||
| # Usage: from airflow.providers.common.compat.lazy_compat import timezone | ||
| # Usage: from airflow.providers.common.compat.sdk import timezone |
There was a problem hiding this comment.
>>> from airflow.providers.common.compat.lazy_compat import timezone
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'airflow.providers.common.compat.lazy_compat'
>>> from airflow.providers.common.compat.sdk import timezone
>>>
Sure @Prab-27, please lemme know if you're occupied with other tasks. I can pick it up as well. |
relates to: #45461
Details
As part of 45461, as far as I understand, only a last couple of
session.queryinstances were left behind:These instances have been replaced with
session.executeandsession.scalars, dependending on their corresponding usages in the source code. Also fixed a potential dangling import issue I ran into with the prek pre-push hook:Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.