fix(sqlite_query): fail the task on a failed query#270
Merged
Conversation
main() ignored the success flag returned by select(), so a failed query exited with changed=false and the error message smuggled into query_result - reporting success for a broken query. Check the flag and call fail_json with the error instead. Add a reusable Ansible module test harness (tests/ansible_harness.py: set_module_args + exit_json/fail_json patching, profile-aware so it works on ansible-core 2.15 through 2.21) and main()-level tests covering both the success and the failure path.
ebuerki-lf
pushed a commit
that referenced
this pull request
May 26, 2026
) main() ignored the success flag returned by select(), so a failed query exited with changed=false and the error message smuggled into query_result - reporting success for a broken query. Check the flag and call fail_json with the error instead. Add a reusable Ansible module test harness (tests/ansible_harness.py: set_module_args + exit_json/fail_json patching, profile-aware so it works on ansible-core 2.15 through 2.21) and main()-level tests covering both the success and the failure path.
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.
First of the deferred behavior-changing fixes.
Bug
main()ignored thesuccessflag fromselect(). A failed query (bad SQL, missing table, ...) exited withchanged=falseand the error message placed intoquery_result, i.e. the module reported success for a broken query.Fix
Check the flag and
fail_jsonwith the error message when the query fails.Behavior change
A query that previously "passed" while actually failing will now correctly fail the task. This is intentional; a playbook that depended on the silent success was already broken.
Test infrastructure
Adds
tests/ansible_harness.py: the standardset_module_args+exit_json/fail_json-patching pattern for unit-testing a module'smain(). It is profile-aware (_ANSIBLE_PROFILE), so it works across ansible-core 2.15 - 2.21.tests/conftest.pyputstests/onsys.pathso test modules canimport ansible_harness. This harness is reused by the upcoming bitwarden / nextcloud behavior fixes.Tests
TestMaincovers both the success path (exit_json with the rows) and the failure path (fail_json on a bad query).Validation
Full tox matrix green (96 tests across 13 envs, incl. ansible-core 2.21).