From d4760712b7f81ac2344cb2aa9648d6a1064a3f48 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Wed, 22 Jan 2025 23:55:56 -0300 Subject: [PATCH] Don't raise exception on inexistent services in 'down' command When running 'podman-compose down ', if service is not part of the compose, a KeyError exception is raised in function 'get_excluded'. By only allowing evaluation of services that exist in the compose provides a cleaner and gentler exit for this case. Signed-off-by: Rafael Guterres Jeffman --- newsfragments/compose_down_inexistent_service.bugfix | 1 + podman_compose.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 newsfragments/compose_down_inexistent_service.bugfix diff --git a/newsfragments/compose_down_inexistent_service.bugfix b/newsfragments/compose_down_inexistent_service.bugfix new file mode 100644 index 0000000..80d9c9c --- /dev/null +++ b/newsfragments/compose_down_inexistent_service.bugfix @@ -0,0 +1 @@ +- Fixed KeyError in case podman-compose down was called with an inexistent service diff --git a/podman_compose.py b/podman_compose.py index 77bb999..df1f9ee 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -2648,7 +2648,8 @@ def get_excluded(compose, args): if args.services: excluded = set(compose.services) for service in args.services: - if not args.no_deps: + # we need 'getattr' as compose_down_parse dose not configure 'no_deps' + if service in compose.services and not getattr(args, "no_deps", False): excluded -= set(x.name for x in compose.services[service]["_deps"]) excluded.discard(service) log.debug("** excluding: %s", excluded)