Don't raise exception on inexistent services in 'down' command

When running 'podman-compose down <service>', 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 <rjeffman@redhat.com>
This commit is contained in:
Rafael Guterres Jeffman 2025-01-22 23:55:56 -03:00
parent 7c61f24467
commit d4760712b7
2 changed files with 3 additions and 1 deletions

View File

@ -0,0 +1 @@
- Fixed KeyError in case podman-compose down was called with an inexistent service

View File

@ -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)