Fix orphan removal: use getattr#1387
Conversation
When exiting podman compose by repeating ctrl+C rapidly, its state may get corrupt and no longer have the remove_orphans attribute. This broke podman compose for me.
There was a problem hiding this comment.
Pull request overview
Makes podman compose down resilient to a corrupted/partial argparse.Namespace by avoiding an AttributeError when remove_orphans is missing (reported when repeatedly hitting Ctrl+C during exit).
Changes:
- Switch
args.remove_orphansaccess togetattr(args, "remove_orphans", False)incompose_down.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| orphaned_images = set() | ||
| if args.remove_orphans: | ||
| if getattr(args, 'remove_orphans', False): |
There was a problem hiding this comment.
Use double quotes for consistency with the rest of this file’s getattr(args, ...) calls (e.g., getattr(args, "timeout", None) a few lines above).
|
|
||
| orphaned_images = set() | ||
| if args.remove_orphans: | ||
| if getattr(args, 'remove_orphans', False): |
There was a problem hiding this comment.
Add test coverage for this regression: compose_down should not raise when args is missing remove_orphans (e.g., an argparse.Namespace constructed without that attribute). This change is user-facing and there are existing unit/integration tests for down, but none cover the missing-attribute scenario.
|
Without exact reproduction steps I cannot merge this PR. It's not possible to verify that the issue actually happens and that this PR fixes it. |
p12tic
left a comment
There was a problem hiding this comment.
Without exact reproduction steps I cannot merge this PR. It's not possible to verify that the issue actually happens and that this PR fixes it.
|
I can't reproduce it either as the interrupt needs to be timed precisely... but it is a state that can occur. |
When exiting podman compose by repeating ctrl+C rapidly, its state may get corrupt and no longer have the remove_orphans attribute. This broke podman compose for me.
Contributor Checklist:
If this PR adds a new feature that improves compatibility with docker-compose, please add a link
to the exact part of compose spec that the PR touches.
For any user-visible change please add a release note to newsfragments directory, e.g.
newsfragments/my_feature.feature. See newsfragments/README.md for more details.
All changes require additional unit tests.