This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5c2dc53bcb Fix autodetect_docker_context for list of dict case (#34779)
5c2dc53bcb is described below

commit 5c2dc53bcb17ae515f9565c41d15cc6d1693382c
Author: Utkarsh Sharma <[email protected]>
AuthorDate: Fri Oct 6 11:59:35 2023 +0530

    Fix autodetect_docker_context for list of dict case (#34779)
    
    * Fix autodetect_docker_context for list of dict case
    
    * Handle the case of dict
---
 dev/breeze/src/airflow_breeze/utils/docker_command_utils.py |  7 ++++++-
 dev/breeze/tests/test_docker_command_utils.py               | 10 ++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py 
b/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
index c77289383a..b68bb38cfd 100644
--- a/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
+++ b/dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
@@ -828,7 +828,12 @@ def autodetect_docker_context():
     if result.returncode != 0:
         get_console().print("[warning]Could not detect docker builder. Using 
default.[/]")
         return "default"
-    context_dicts = (json.loads(line) for line in result.stdout.splitlines() 
if line.strip())
+    try:
+        context_dicts = json.loads(result.stdout)
+        if isinstance(context_dicts, dict):
+            context_dicts = [context_dicts]
+    except json.decoder.JSONDecodeError:
+        context_dicts = (json.loads(line) for line in 
result.stdout.splitlines() if line.strip())
     known_contexts = {info["Name"]: info for info in context_dicts}
     if not known_contexts:
         get_console().print("[warning]Could not detect docker builder. Using 
default.[/]")
diff --git a/dev/breeze/tests/test_docker_command_utils.py 
b/dev/breeze/tests/test_docker_command_utils.py
index 234904a668..00749ccbc0 100644
--- a/dev/breeze/tests/test_docker_command_utils.py
+++ b/dev/breeze/tests/test_docker_command_utils.py
@@ -228,6 +228,16 @@ def _fake_ctx_output(*names: str) -> str:
             "desktop-linux",
             "[info]Using desktop-linux as context",
         ),
+        (
+            _fake_ctx_output("a", "default", "desktop-linux"),
+            "desktop-linux",
+            "[info]Using desktop-linux as context",
+        ),
+        (
+            '[{"Name": "desktop-linux", "DockerEndpoint": 
"unix://desktop-linux"}]',
+            "desktop-linux",
+            "[info]Using desktop-linux as context",
+        ),
     ],
 )
 def test_autodetect_docker_context(context_output: str, selected_context: str, 
console_output: str):

Reply via email to