Skip to content

fix: close rows before nested queries to prevent PostgreSQL driver error#1503

Open
osalloum wants to merge 3 commits intoTwiN:masterfrom
osalloum:fix/postgresql-suites-nested-query
Open

fix: close rows before nested queries to prevent PostgreSQL driver error#1503
osalloum wants to merge 3 commits intoTwiN:masterfrom
osalloum:fix/postgresql-suites-nested-query

Conversation

@osalloum
Copy link

Summary

This PR fixes the pq: unexpected Parse response 'C' error that occurs when using PostgreSQL storage with suites (issue #1435).

The root cause is that the lib/pq PostgreSQL driver requires the previous query to be fully closed before starting new queries in the same transaction. Without this, attempting nested queries results in the cryptic "unexpected Parse response" error.

Changes

The fix applies to two locations in storage/store/sql/sql.go:

  1. GetAllSuiteStatuses: Changed to collect all suite data first into a slice, close the rows, then iterate over the collected data to call getSuiteResults for each suite.

  2. getSuiteResults: Added explicit rows.Close() after iterating through suite results and before making nested queries to fetch endpoint results.

Testing

  • Added a new PostgreSQL integration test (TestPostgresSuiteResultsNestedQuery) using embedded-postgres to verify the fix works and prevent regression
  • The test creates multiple suite results with endpoint results and condition results, then retrieves them using GetAllSuiteStatuses and GetSuiteStatusByKey
  • All existing tests continue to pass

Related Issue

Fixes #1435

🤖 Generated with Claude Code

This fixes the "pq: unexpected Parse response 'C'" error that occurs when
using PostgreSQL storage with suites. The lib/pq driver requires the previous
query to be fully closed before starting new queries in the same transaction.

The fix applies to two locations:
1. GetAllSuiteStatuses: Collect all suite data first, close rows, then
   iterate to call getSuiteResults for each suite
2. getSuiteResults: Close rows after iterating before fetching endpoint
   results in nested queries

Added a PostgreSQL integration test using embedded-postgres to verify
the fix and prevent regression.

Fixes TwiN#1435

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added the bug Something isn't working label Jan 21, 2026
@osalloum osalloum force-pushed the fix/postgresql-suites-nested-query branch from c92da59 to 7c7bd1d Compare January 21, 2026 22:27
@osalloum osalloum requested a review from TwiN January 23, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with PostgreSQL and Suites module

2 participants