Skip to content

fix(sqlite_query): fail the task on a failed query#270

Merged
markuslf merged 1 commit into
mainfrom
fix/sqlite-query-fail-on-error
May 25, 2026
Merged

fix(sqlite_query): fail the task on a failed query#270
markuslf merged 1 commit into
mainfrom
fix/sqlite-query-fail-on-error

Conversation

@markuslf
Copy link
Copy Markdown
Member

First of the deferred behavior-changing fixes.

Bug

main() ignored the success flag from select(). A failed query (bad SQL, missing table, ...) exited with changed=false and the error message placed into query_result, i.e. the module reported success for a broken query.

Fix

Check the flag and fail_json with 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 standard set_module_args + exit_json/fail_json-patching pattern for unit-testing a module's main(). It is profile-aware (_ANSIBLE_PROFILE), so it works across ansible-core 2.15 - 2.21. tests/conftest.py puts tests/ on sys.path so test modules can import ansible_harness. This harness is reused by the upcoming bitwarden / nextcloud behavior fixes.

Tests

TestMain covers 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).

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.
@markuslf markuslf requested a review from NavidSassan May 25, 2026 08:13
@markuslf markuslf merged commit b472d49 into main May 25, 2026
11 checks passed
@markuslf markuslf deleted the fix/sqlite-query-fail-on-error branch May 25, 2026 08:33
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.
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