You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Pyasma (via GitHub)" <gi...@apache.org> on 2025/12/11 20:29:30 UTC

[PR] Fix/connection uri [airflow]

Pyasma opened a new pull request, #59339:
URL: https://github.com/apache/airflow/pull/59339

   <!--
    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/
   -->
   
   RE:This PR fixes how Connection.get_uri() handles extras with non-string values (floats, booleans, nested dicts).
   
   Extras are now stringified before encoding to produce valid, SQLAlchemy-compatible URIs.
   
   Added a unit test test_get_uri_with_non_string_extras to verify the change.
   
   All pre-commit checks passed.
   
   Issue :https://github.com/apache/airflow/issues/55893
   
   Original PR is closed -> https://github.com/apache/airflow/pull/57969
   
   <!-- 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: commits-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3660969923

   @jason810496 Hey jason can you please review the PR


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3652778279

   > Nice all test passed thanks @potiuk @henry3260 
   > 
   > The issue is solved now? 
   
   Yes 😀 


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650308397

   Hey @potiuk, thanks for re-running the tests. I’m a bit confused by these errors—do you have any advice on where I should start looking or how to approach fixing them?


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #59339:
URL: https://github.com/apache/airflow/pull/59339#discussion_r2639805649


##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -457,14 +470,14 @@ def get_extra_dejson(self, nested: bool = False) -> dict:
 
         if self.extra:
             try:
+                extra = json.loads(self.extra)
                 if nested:
-                    for key, value in json.loads(self.extra).items():
-                        extra[key] = value
+                    for key, value in extra.items():
                         if isinstance(value, str):
-                            with suppress(JSONDecodeError):
+                            try:
                                 extra[key] = json.loads(value)
-                else:
-                    extra = json.loads(self.extra)
+                            except (JSONDecodeError, TypeError):
+                                pass

Review Comment:
   I think we could revert the change of `get_extra_dejson`, thanks!



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3745736115

   > After migration to 3.1.6 still having error:
   > 
   > 
   > 
   > `[2026-01-13 15:46:29] ERROR - Task failed with exception source=task loc=task_runner.py:1056
   > 
   > AirflowException: ('Entra Id processing error:', TypeError("connect() got an unexpected keyword argument '__extra__'"))
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1004 in run
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1405 in _execute_task
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 417 in wrapper
   > 
   > 
   > 
   > File "/opt/airflow/plugins/com/softwaremind/transfers/entraid.py", line 148 in execute
   > 
   > 
   > 
   > TypeError: connect() got an unexpected keyword argument '__extra__'
   > 
   > File "/opt/airflow/plugins/com/softwaremind/transfers/entraid.py", line 133 in execute
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/providers/microsoft/mssql/hooks/mssql.py", line 97 in get_sqlalchemy_connection
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3325 in connect
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 96 in __init__
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3404 in raw_connection
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3371 in _wrap_pool_connect
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 327 in connect
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 894 in _checkout
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 493 in checkout
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py", line 145 in _do_get
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 70 in __exit__
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211 in raise_
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py", line 143 in _do_get
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 273 in _create_connection
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 388 in __init__
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 690 in __connect
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 70 in __exit__
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211 in raise_
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 686 in __connect
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 574 in connect
   > 
   > 
   > 
   > File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 598 in connect`
   > 
   > 
   > 
   > When extra fields contains as_dict attribute:
   > 
   > 
   > 
   > `{
   > 
   >   "tds_version": "7.3",
   > 
   >   "as_dict": true
   > 
   > }`
   
   Can you open an issue for that?
   Thanks!


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3720118509

   hey @jason810496 @potiuk  Sorry i missed the message


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650440884

   > Hey @potiuk, thanks for re-running the tests. I’m a bit confused by these errors—do you have any advice on where I should start looking or how to approach fixing them?
   
   There was a flaky test in main - so it failed often in other PRs as well. This is now hopefully fixed in https://github.com/apache/airflow/pull/59394  so you should not worry about it.


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650679927

   Yeah. Not your fault for sure. I have a likely fix for the main issue: https://github.com/apache/airflow/pull/59406


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #59339:
URL: https://github.com/apache/airflow/pull/59339#discussion_r2626174989


##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -331,14 +335,23 @@ def get_uri(self) -> str:
 
         if self.extra:
             try:
-                query: str | None = urlencode(self.extra_dejson)
-            except TypeError:
-                query = None
-            if query and self.extra_dejson == dict(parse_qsl(query, keep_blank_values=True)):
-                uri += ("?" if self.schema else "/?") + query
-            else:
+                extra_dict = self.extra_dejson
+                can_flatten = True
+                for _, value in extra_dict.items():

Review Comment:
   ```suggestion
                   for value in extra_dict.values():
   ```



##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -252,6 +251,11 @@ def _parse_from_uri(self, uri: str):
             if self.EXTRA_KEY in query:
                 self.extra = query[self.EXTRA_KEY]
             else:
+                for key, value in query.items():
+                    try:
+                        query[key] = json.loads(value)
+                    except (JSONDecodeError, TypeError):
+                        pass

Review Comment:
   Worth adding a log here. probably debug or info



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3682487886

   sorry about this push i am gonna push one more time i forgot to do prek test 


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on code in PR #59339:
URL: https://github.com/apache/airflow/pull/59339#discussion_r2640211445


##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -330,15 +334,22 @@ def get_uri(self) -> str:
         uri += host_block
 
         if self.extra:
+            extra_dict = self.extra_dejson
+            can_flatten = True
+            for value in extra_dict.values():
+                if not isinstance(value, str):
+                    can_flatten = False
+                    break
+
             try:
-                query: str | None = urlencode(self.extra_dejson)
+                query = urlencode(extra_dict)

Review Comment:
   sorry about this i added it again



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3660972256

   hey @Lee-W Can you please review the PR


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650637581

   test still failed though :smiling_face_with_tear: 
   I will look at it later any advice for this one ?


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3652707725

   Nice all test passed thanks @potiuk @henry3260 
   
   The issue is solved now? 


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3645853720

   > CodeQL workflow is awaiting maintainer approval (standard for PRs from forks). All unit tests pass locally. @jason810496 @Lee-W
   
   Can you review this please


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650643118

   Yep. the `hopefully` part was unfortunatelly well placed.


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #59339:
URL: https://github.com/apache/airflow/pull/59339


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3693945654

   Sorry that I forgot to add the backport label. @Pyasma, would you mind backporting this PR to the `v3-1-test` branch? Thanks!
   
   We can backport the patch using the following command and resolve any conflicts if needed:
   
   ```bash
   cherry_picker a377033 v3-1-test
   ```
   


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #59339:
URL: https://github.com/apache/airflow/pull/59339#discussion_r2639805649


##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -457,14 +470,14 @@ def get_extra_dejson(self, nested: bool = False) -> dict:
 
         if self.extra:
             try:
+                extra = json.loads(self.extra)
                 if nested:
-                    for key, value in json.loads(self.extra).items():
-                        extra[key] = value
+                    for key, value in extra.items():
                         if isinstance(value, str):
-                            with suppress(JSONDecodeError):
+                            try:
                                 extra[key] = json.loads(value)
-                else:
-                    extra = json.loads(self.extra)
+                            except (JSONDecodeError, TypeError):
+                                pass

Review Comment:
   I think we could revert the change of `get_extra_dejson`, as  current change doesn't impact the behavior.Thanks!



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3645851747

   CodeQL workflow is awaiting maintainer approval (standard for PRs from forks). All unit tests pass locally.
   @jason810496 
   @Lee-W 
   


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Pyasma (via GitHub)" <gi...@apache.org>.
Pyasma commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3693667732

   @jason810496 @Lee-W Thanks for approving the PR can you merge this to main?


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "frodo2000 (via GitHub)" <gi...@apache.org>.
frodo2000 commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3744787393

   After migration to 3.1.6 still having error:
   
   `[2026-01-13 15:46:29] ERROR - Task failed with exception source=task loc=task_runner.py:1056
   AirflowException: ('Entra Id processing error:', TypeError("connect() got an unexpected keyword argument '__extra__'"))
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1004 in run
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1405 in _execute_task
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 417 in wrapper
   
   File "/opt/airflow/plugins/com/softwaremind/transfers/entraid.py", line 148 in execute
   
   TypeError: connect() got an unexpected keyword argument '__extra__'
   File "/opt/airflow/plugins/com/softwaremind/transfers/entraid.py", line 133 in execute
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/airflow/providers/microsoft/mssql/hooks/mssql.py", line 97 in get_sqlalchemy_connection
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3325 in connect
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 96 in __init__
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3404 in raw_connection
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 3371 in _wrap_pool_connect
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 327 in connect
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 894 in _checkout
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 493 in checkout
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py", line 145 in _do_get
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 70 in __exit__
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211 in raise_
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/impl.py", line 143 in _do_get
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 273 in _create_connection
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 388 in __init__
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 690 in __connect
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/langhelpers.py", line 70 in __exit__
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/util/compat.py", line 211 in raise_
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/pool/base.py", line 686 in __connect
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/create.py", line 574 in connect
   
   File "/home/airflow/airflow_venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 598 in connect`
   
   When extra fields contains as_dict attribute:
   
   `{
     "tds_version": "7.3",
     "as_dict": true
   }`


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3719213955

   I cherry-picked it here https://github.com/apache/airflow/pull/60219 @jason810496 


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650599834

   Same 🫠 


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "henry3260 (via GitHub)" <gi...@apache.org>.
henry3260 commented on PR #59339:
URL: https://github.com/apache/airflow/pull/59339#issuecomment-3650643519

   > test still failed though :smiling_face_with_tear: 
   > 
   > I will look at it later any advice for this one ?
   
   Don't worry. It's not you fault


-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #59339:
URL: https://github.com/apache/airflow/pull/59339#discussion_r2625560498


##########
airflow-core/tests/unit/models/test_connection.py:
##########
@@ -148,6 +148,17 @@ def clear_fernet_cache(self):
                 None,
                 r"Invalid connection string: type://user:pass@protocol://host:port?param=value.",
             ),
+            (
+                "type://host?int_param=123&bool_param=true&float_param=1.5&str_param=some_str",
+                "type",
+                "host",
+                None,
+                None,
+                None,
+                "",
+                {"int_param": 123, "bool_param": True, "float_param": 1.5, "str_param": "some_str"},
+                None,
+            ),

Review Comment:
   Could we add another case that include `__extra__` in the URI to check whether the `parse_from_uri` are still able to parse the new encoding logic?



##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -331,14 +335,23 @@ def get_uri(self) -> str:
 
         if self.extra:
             try:
-                query: str | None = urlencode(self.extra_dejson)
-            except TypeError:
-                query = None
-            if query and self.extra_dejson == dict(parse_qsl(query, keep_blank_values=True)):
-                uri += ("?" if self.schema else "/?") + query
-            else:
+                extra_dict = self.extra_dejson
+                can_flatten = True
+                for _, value in extra_dict.items():
+                    if not isinstance(value, str):
+                        can_flatten = False
+                        break

Review Comment:
   How about moving the `can_flatten` logic before the `try` block, as it _should_ not raise any `TypeError, AttributeError` exception.



##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -457,14 +470,14 @@ def get_extra_dejson(self, nested: bool = False) -> dict:
 
         if self.extra:
             try:
+                extra = json.loads(self.extra)
                 if nested:
-                    for key, value in json.loads(self.extra).items():
-                        extra[key] = value
+                    for key, value in extra.items():
                         if isinstance(value, str):
-                            with suppress(JSONDecodeError):
+                            try:
                                 extra[key] = json.loads(value)
-                else:
-                    extra = json.loads(self.extra)
+                            except (JSONDecodeError, TypeError):
+                                pass

Review Comment:
   Sorry for pointing you in the wrong direction in my last review.
   After double-checking, we don’t need to change `get_extra_dejson` at all.



##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -331,14 +335,23 @@ def get_uri(self) -> str:
 
         if self.extra:
             try:
-                query: str | None = urlencode(self.extra_dejson)
-            except TypeError:
-                query = None
-            if query and self.extra_dejson == dict(parse_qsl(query, keep_blank_values=True)):
-                uri += ("?" if self.schema else "/?") + query
-            else:
+                extra_dict = self.extra_dejson
+                can_flatten = True
+                for _, value in extra_dict.items():
+                    if not isinstance(value, str):
+                        can_flatten = False
+                        break
+
+                if can_flatten:
+                    query = urlencode(extra_dict)
+                    if extra_dict == dict(parse_qsl(query, keep_blank_values=True)):
+                        uri += ("?" if self.schema else "/?") + query
+                    else:
+                        uri += ("?" if self.schema else "/?") + urlencode({self.EXTRA_KEY: self.extra})
+                else:
+                    uri += ("?" if self.schema else "/?") + urlencode({self.EXTRA_KEY: self.extra})
+            except (TypeError, AttributeError):

Review Comment:
   It seems the whole flow could be simplify as:
   
   ```python
   can_flatten = True
   # the for loop to check whether could we flatten 
   
   try:
       query: str | None = urlencode(self.extra_dejson)
   except TypeError:
       query = None
   
   # we just need to add can_flatten condition check
   if can_flatten and query and self.extra_dejson == dict(parse_qsl(query, keep_blank_values=True)):
       uri += ("?" if self.schema else "/?") + query
   else:
   # fallback to nested EXTRA_KEY
       uri += ("?" if self.schema else "/?") + urlencode({self.EXTRA_KEY: self.extra})
   ```
   
   which also minimized the change.



-- 
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-unsubscribe@airflow.apache.org

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


Re: [PR] Fix/RE:Invalid uri created when extras contains non string elements [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #59339:
URL: https://github.com/apache/airflow/pull/59339#discussion_r2639136257


##########
airflow-core/src/airflow/models/connection.py:
##########
@@ -330,15 +334,22 @@ def get_uri(self) -> str:
         uri += host_block
 
         if self.extra:
+            extra_dict = self.extra_dejson
+            can_flatten = True
+            for value in extra_dict.values():
+                if not isinstance(value, str):
+                    can_flatten = False
+                    break
+
             try:
-                query: str | None = urlencode(self.extra_dejson)
+                query = urlencode(extra_dict)

Review Comment:
   would like to know why did we remove type annotation



-- 
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-unsubscribe@airflow.apache.org

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