Skip to content

Conversation

@mammo0
Copy link

@mammo0 mammo0 commented Dec 15, 2025

Hello,

I have a docker-compose.yaml file that uses the extends attributes and resets the ports of the extended file:

services:
  test:
    extends:
      file: parent-compose.yaml
      service: extended_service
    ports: !reset []

Unfortunately this results in the following error:

Traceback (most recent call last):
  File "***/podman-compose/podman_compose.py", line 4520, in <module>
    main()
    ~~~~^^
  File "***/podman-compose/podman_compose.py", line 4516, 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 "***/podman-compose/podman_compose.py", line 4512, in async_main
    await podman_compose.run()
  File "***/podman-compose/podman_compose.py", line 2135, in run
    self._parse_compose_file()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "***/podman-compose/podman_compose.py", line 2409, in _parse_compose_file
    self.merged_yaml = yaml.safe_dump(compose)
                       ~~~~~~~~~~~~~~^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/yaml/__init__.py", line 269, in safe_dump
    return dump_all([data], stream, Dumper=SafeDumper, **kwds)
  File "/usr/lib/python3.13/site-packages/yaml/__init__.py", line 241, in dump_all
    dumper.represent(data)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 58, in represent_data
    node = self.yaml_representers[None](self, data)
  File "/usr/lib/python3.13/site-packages/yaml/representer.py", line 231, in represent_undefined
    raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', <__main__.ResetTag object at 0x7fce2419c980>)

I fixed this problem by setting the dumper for the OverrideTag and ResetTag classes to yaml.SafeDumper. Otherwise these classes wont be used by the safe_dump method that is used by podman-compose.

Additionally those custom tag classes caused some further problems, when the compose dictionary is converted to a JSON string using json.dumps(). Therefore I extended the original_service method to cover also nested dictionaries.

-> can now handle recursive dictionaries
-> the new method can be used for services and whole compose objects

Signed-off-by: mammo0 <[email protected]>
Signed-off-by: mammo0 <[email protected]>
@mammo0 mammo0 force-pushed the fix-reset-tag-with-extends branch from 3ff433c to fc42774 Compare December 15, 2025 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant