podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

Unable to run any command due to `AttributeError: 'str' object has no attribute 'get'` exception

Open NexusSfan opened this issue 1 year ago • 6 comments

Describe the bug Whenever I try to run any command under podman-compose, it throws an exception that AttributeError: 'str' object has no attribute 'get'.

To Reproduce Steps to reproduce the behavior:

  1. Try to run any command under podman-compose (for example podman compose up

Expected behavior The command would work.

Actual behavior It throws an exception.

Output

$ podman-compose up
Traceback (most recent call last):
  File "/home/nexussfan/podman_compose.py", line 3554, in <module>
    main()
  File "/home/nexussfan/podman_compose.py", line 3550, in main
    asyncio.run(async_main())
  File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/nexussfan/podman_compose.py", line 3546, in async_main
    await podman_compose.run()
  File "/home/nexussfan/podman_compose.py", line 1773, in run
    self._parse_compose_file()
  File "/home/nexussfan/podman_compose.py", line 1890, in _parse_compose_file
    resolved_services = self._resolve_profiles(compose.get("services", {}), set(args.profile))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nexussfan/podman_compose.py", line 2053, in _resolve_profiles
    service_profiles = set(config.get("profiles", []))
                           ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

Environment:

  • OS: Linux (Debian 13)
  • podman version: 5.2.5
  • podman compose version: 122a914b9b1e278e8d062e5755ca8a602306f416

NexusSfan avatar Nov 01 '24 22:11 NexusSfan

It was a faulty compose file.

NexusSfan avatar Nov 03 '24 18:11 NexusSfan

@NexusSfan Do you have the old compose file somewhere around? We could add a better error message

p12tic avatar Feb 07 '25 10:02 p12tic

Hi @p12tic I'm having this same issue.

compose file:

services:
  postgres:
    image: docker.io/postgres:${CONFIG_VERSION}
    command: /postgres-init.sh
    volumes:
    - socket:/var/run/postgresql
    - ../../../tests/data/postgres-init.sh:/postgres-init.sh:ro
    - ../../../tests/data/ca:/certs:ro
    environment:
    - POSTGRES_USER=vector
    - POSTGRES_PASSWORD=vector
volumes:
  socket: {}
networks:
  default:
    external: 'true'
    name: vector-integration-tests-postgres

I think ${CONFIG_VERSION} is what is causing this problem. I hope this serves as a reproducible example

jorgehermo9 avatar Feb 07 '25 16:02 jorgehermo9

@NexusSfan Do you have the old compose file somewhere around? We could add a better error message

I have created a compose file that has the same error.

services:
    # this_line_commented_out_causes_the_crash:
        image: alpine
        container_name: test

It seems that the type of a service is never checked. In this compose, the image and container_name are assumed to be services since that is the parent, and it tries to use a function which doesn't exist on strings.

Hi @p12tic I'm having this same issue.

[snip]

I think ${CONFIG_VERSION} is what is causing this problem. I hope this serves as a reproducible example

Same error name but different cause. (environment variables)

Traceback on the new faulty Compose file
Traceback (most recent call last):
  File "/usr/bin/podman-compose", line 33, in <module>
    sys.exit(load_entry_point('podman-compose==1.2.0', 'console_scripts', 'podman-compose')())
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/podman_compose.py", line 3504, in main
    asyncio.run(async_main())
    ~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 720, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/podman_compose.py", line 3500, in async_main
    await podman_compose.run()
  File "/usr/lib/python3/dist-packages/podman_compose.py", line 1741, in run
    self._parse_compose_file()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/podman_compose.py", line 1860, in _parse_compose_file
    resolved_services = self._resolve_profiles(compose.get("services", {}), set(args.profile))
  File "/usr/lib/python3/dist-packages/podman_compose.py", line 2019, in _resolve_profiles
    service_profiles = set(config.get("profiles", []))
                           ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

NexusSfan avatar Feb 08 '25 00:02 NexusSfan

Sorry, didn't notice your reply.

p12tic avatar May 30 '25 10:05 p12tic

Tested on podman-compose version 1.4.0, still errors.

View Traceback
Traceback (most recent call last):
  File "/home/nexussfan/podman/venv/bin/podman-compose", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/nexussfan/podman/venv/lib/python3.13/site-packages/podman_compose.py", line 3995, in main
    asyncio.run(async_main())
    ~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/nexussfan/podman/venv/lib/python3.13/site-packages/podman_compose.py", line 3991, in async_main
    await podman_compose.run()
  File "/home/nexussfan/podman/venv/lib/python3.13/site-packages/podman_compose.py", line 1982, in run
    self._parse_compose_file()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/nexussfan/podman/venv/lib/python3.13/site-packages/podman_compose.py", line 2134, in _parse_compose_file
    resolved_services = self._resolve_profiles(compose.get("services", {}), set(args.profile))
  File "/home/nexussfan/podman/venv/lib/python3.13/site-packages/podman_compose.py", line 2309, in _resolve_profiles
    service_profiles = set(config.get("profiles", []))
                           ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'

As I said in a previous reply, this could be fixed by checking if the object type is a dict (I'm guessing that's the correct type based off the traceback) before using a dict specific function.

NexusSfan avatar May 30 '25 14:05 NexusSfan