Unable to run any command due to `AttributeError: 'str' object has no attribute 'get'` exception
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:
- Try to run any command under
podman-compose(for examplepodman 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
It was a faulty compose file.
@NexusSfan Do you have the old compose file somewhere around? We could add a better error message
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
@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'
Sorry, didn't notice your reply.
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.