Skip to content

Commit

Permalink
Fix autodetect_docker_context for list of dict case (apache#34779)
Browse files Browse the repository at this point in the history
* Fix autodetect_docker_context for list of dict case

* Handle the case of dict
  • Loading branch information
utkarsharma2 authored Oct 6, 2023
1 parent 59ed537 commit 5c2dc53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.[/]")
Expand Down
10 changes: 10 additions & 0 deletions dev/breeze/tests/test_docker_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5c2dc53

Please sign in to comment.