Skip to content

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

Merged
TwiN merged 7 commits intoTwiN:masterfrom
osalloum:fix/postgresql-suites-nested-query
Apr 19, 2026
Merged

fix(storage): close rows before nested queries to prevent PostgreSQL driver error#1503
TwiN merged 7 commits intoTwiN:masterfrom
osalloum:fix/postgresql-suites-nested-query

Conversation

@osalloum
Copy link
Copy Markdown
Contributor

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

@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
Comment thread storage/store/sql/sql.go Outdated
@osalloum osalloum requested a review from TwiN January 23, 2026 18:45
osalloum and others added 3 commits March 3, 2026 01:52
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 <noreply@anthropic.com>
@osalloum osalloum force-pushed the fix/postgresql-suites-nested-query branch from 18bb154 to a3bfb9d Compare March 3, 2026 00:53
@osalloum
Copy link
Copy Markdown
Contributor Author

osalloum commented Mar 3, 2026

Hey sorry to bother again, is there anything further I can do to get this merged?

Copy link
Copy Markdown
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the test you added for postgres.

Weird suggestion, I know, but I've had too many issues with that library in the past

Remove the embedded-postgres test per maintainer request.
@osalloum osalloum requested a review from TwiN April 14, 2026 12:31
@TwiN TwiN changed the title fix: close rows before nested queries to prevent PostgreSQL driver error fix(storage): close rows before nested queries to prevent PostgreSQL driver error Apr 18, 2026
@TwiN TwiN added the area/storage Related to storage label Apr 18, 2026
@TwiN TwiN merged commit bc43316 into TwiN:master Apr 19, 2026
2 checks passed
@TwiN
Copy link
Copy Markdown
Owner

TwiN commented Apr 19, 2026

Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/storage Related to storage 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