amoghrajesh opened a new pull request, #54261:
URL: https://github.com/apache/airflow/pull/54261
<!--
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.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
### Why?
While working on https://github.com/apache/airflow/pull/54083, I happened to
notice that the kube system tests started failing with:
```
../task-sdk/src/airflow/sdk/bases/operator.py:403: in wrapper
return func(self, *args, **kwargs)
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:642:
in execute
return self.execute_sync(context)
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:650:
in execute_sync
self.pod_request_obj = self.build_pod_request_obj(context)
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py:1289:
in build_pod_request_obj
"airflow_kpo_in_cluster": str(self.hook.is_in_cluster),
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:307:
in is_in_cluster
self.api_client # so we can determine if we are in_cluster or not
/opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/functools.py:981: in
__get__
val = self.func(instance)
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:315:
in api_client
return self.get_conn()
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:215:
in get_conn
in_cluster = self._coalesce_param(self.in_cluster,
self._get_field("in_cluster"))
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:208:
in _get_field
if field_name in self.conn_extras:
/opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/functools.py:981: in
__get__
val = self.func(instance)
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:189:
in conn_extras
connection = self.get_connection(self.conn_id)
../providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/hooks/kubernetes.py:180:
in get_connection
return super().get_connection(conn_id) # type: ignore[return-value]
../task-sdk/src/airflow/sdk/bases/hook.py:61: in get_connection
conn = Connection.get(conn_id)
../task-sdk/src/airflow/sdk/definitions/connection.py:154: in get
return _get_connection(conn_id)
```
The reason for this is that those tests used a mock on `get_connection`
which is mid-way to the entire flow of getting a connection (models connection
had an internal `get_connection` defined on connection backends and this test
was bypassing it). The current `mock_get_connection` fixture uses `mock.patch`
to return a minimal `Connection` object with only `conn_id` set.
A better OR more complete pattern would be to actual create the connection
using env vars on the host machine as part of the test setup that runs, that
would ensure that no unneccessary mocking is performed and Connection retrieval
flow works normally (backend > env > api server)
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information.
In case of fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a
newsfragment file, named `{pr_number}.significant.rst` or
`{issue_number}.significant.rst`, in
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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]