Only persist parameters after a successful playbook run#118
Conversation
|
This seems to solve the similar issue #109 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
WalkthroughThis PR refactors CLI argument persistence by extracting inline logic from Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@obsah/__init__.py`:
- Around line 598-599: The persist_args(...) call can raise I/O exceptions and
currently would make the process exit nonzero even when exit_code == 0; wrap the
call to persist_args(application_config, args, parser.obsah_dont_persist) in a
try/except that catches Exception (or more specific I/O errors like
PermissionError/OSError), log the exception (use the module logger or existing
logger variable) at error level, but do not change or override exit_code so a
successful playbook outcome remains successful; ensure this handling is placed
where application_config.persist_params() and exit_code == 0 are checked.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c3803399-61c5-4a23-a0d5-a1b0ad94a611
📒 Files selected for processing (2)
obsah/__init__.pytests/test_reset.py
d0fecb0 to
676cbfd
Compare
Parameters were persisted to parameters.yaml before the playbook executed, meaning invalid values (e.g. unknown features) would be written to disk even when the playbook rejected them. On subsequent runs the invalid values were loaded back as defaults, creating a persistent failure loop. Move persistence to after playbook execution and gate it on a zero exit code so only validated parameters are saved. If persistence itself fails (e.g. permission error), print an error to stderr and exit non-zero so the failure is not silently swallowed. Rename test_reset.py to test_parameter_persistence.py and refactor fixtures to derive persist_path from state_path rather than overriding it directly. Add a test covering the no-persistence-on-failure case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
676cbfd to
cf55f94
Compare
Parameters were persisted to parameters.yaml before the playbook executed, meaning invalid values (e.g. unknown features) would be written to disk even when the playbook rejected them. On subsequent runs the invalid values were loaded back as defaults, creating a persistent failure loop.
Move persistence to after playbook execution and gate it on a zero exit code so only validated parameters are saved.
If, for example, I run:
And
foo-baris not an actual feature, I will get an error message butfoo-barwill now be in the features list. This happens consistently if you run the./forge testcommand due to https://github.com/theforeman/foremanctl/blob/6e99e94f86956f189a29886591915ae568180901/tests/features_test.py#L24