ipauser: Fix query state error handling and per-field conversion errors - #1428
Merged
Conversation
query_convert_result now reports the failing field name per-key instead of aborting the whole loop with an unrelated try/except scope. main() also rejects state=query with action=member and query is excluded from rename's generated args and PARAM_MAPPING query fields.
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In check_parameters(), the new state == "query" fail_json makes the subsequent state == "query" branch that appends "users" to invalid unreachable; consider consolidating these into a single block or removing the dead code.
- The error message "users can not be used with state=query" in main() is still raised when state != "query" (same as before), which can be confusing for users; consider updating the message to reflect the actual condition under which it fires.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In check_parameters(), the new state == "query" fail_json makes the subsequent state == "query" branch that appends "users" to invalid unreachable; consider consolidating these into a single block or removing the dead code.
- The error message "users can not be used with state=query" in main() is still raised when state != "query" (same as before), which can be confusing for users; consider updating the message to reflect the actual condition under which it fires.
## Individual Comments
### Comment 1
<location path="plugins/modules/ipauser.py" line_range="887" />
<code_context>
invalid.extend(
["principal", "manager", "certificate", "certmapdata"])
+ if state == "query":
+ module.fail_json(
+ msg="check_parameters can not be used with action query.")
if state == "query":
invalid.append("users")
</code_context>
<issue_to_address>
**issue (bug_risk):** The second `if state == "query"` branch is unreachable after `fail_json`, which suggests either redundant or misstructured logic.
Because `module.fail_json(...)` aborts execution, the second `if state == "query": invalid.append("users")` is now unreachable. Decide whether you want an immediate hard-fail for `check_parameters`+`query` (in which case the `invalid.append("users")` branch should be removed), or to keep the previous behavior of populating `invalid` and handling it later (in which case the first `if` likely needs to be an `elif` or merged into the branch that examines `invalid`).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| invalid.extend( | ||
| ["principal", "manager", "certificate", "certmapdata"]) | ||
|
|
||
| if state == "query": |
There was a problem hiding this comment.
issue (bug_risk): The second if state == "query" branch is unreachable after fail_json, which suggests either redundant or misstructured logic.
Because module.fail_json(...) aborts execution, the second if state == "query": invalid.append("users") is now unreachable. Decide whether you want an immediate hard-fail for check_parameters+query (in which case the invalid.append("users") branch should be removed), or to keep the previous behavior of populating invalid and handling it later (in which case the first if likely needs to be an elif or merged into the branch that examines invalid).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
query_convert_result now reports the failing field name per-key instead of aborting the whole loop with an unrelated try/except scope. main() also rejects state=query with action=member and query is excluded from rename's generated args and PARAM_MAPPING query fields.
Summary by Sourcery
Improve ipauser query handling by reporting per-field conversion errors and tightening invalid state/action and parameter combinations for query operations.
Bug Fixes: