Skip to content

fix(store): return transaction errors from rql search repositories#1768

Open
AmanGIT07 wants to merge 5 commits into
mainfrom
fix/search-txn-errors
Open

fix(store): return transaction errors from rql search repositories#1768
AmanGIT07 wants to merge 5 commits into
mainfrom
fix/search-txn-errors

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

Search methods in four rql repositories discarded the error returned by WithTxn. A failed transaction begin or commit produced an empty result with no error.

Changes

  • Capture and return the WithTxn error in OrgBillingRepository.Search, OrgProjectsRepository.Search, OrgUsersRepository.Search, and ProjectUsersRepository.Search

Technical Details

WithTxn returns errors from transaction begin, commit, and the callback. Only callback errors reached the caller, through a captured outer variable. In OrgBillingRepository.Search the group-by branch shadowed that variable, so its failures were dropped as well.

Test Plan

  • go test ./internal/store/postgres/ passes (covers the four Search methods)
  • Build and type checking passes

SQL Safety (if your PR touches *_repository.go or goqu.*)

  • Values flow through ? placeholders, goqu.Ex{}, or goqu.Record{} — never fmt.Sprintf or + building a query that gets executed.
  • ToSQL() callers capture and forward params (query, params, err := stmt.ToSQL(); db.…Context(ctx, …, query, params...)). Never query, _, err := ….
  • No ? placeholders inside single-quoted SQL literals in goqu.L (use make_interval(hours => ?)-style functions instead).
  • Any //nolint:forbidigo or // #nosec G20x annotation has a one-line justification on the same line that a reviewer can verify.

WithTxn's return value was discarded in the org billing, org projects,
org users, and project users search methods. A failed transaction begin
or commit returned empty results with no error.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jul 22, 2026 8:56am

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dd74366b-3690-4568-8a66-4b419c0a86df

📥 Commits

Reviewing files that changed from the base of the PR and between 9c6bba8 and fc8e020.

📒 Files selected for processing (5)
  • internal/store/postgres/fakes_test.go
  • internal/store/postgres/org_billing_repository_test.go
  • internal/store/postgres/org_projects_repository_test.go
  • internal/store/postgres/org_users_repository_test.go
  • internal/store/postgres/project_users_repository_test.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • internal/store/postgres/project_users_repository_test.go
  • internal/store/postgres/org_projects_repository_test.go
  • internal/store/postgres/org_billing_repository_test.go
  • internal/store/postgres/fakes_test.go
  • internal/store/postgres/org_users_repository_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved Search behavior so errors from failing to start a database transaction are reliably propagated and returned for billing, projects, org users, and project users.
  • Tests

    • Added a deterministic transaction-failure test helper.
    • Added unit tests confirming each affected Search method returns an error when a transaction cannot be started.

Walkthrough

Four PostgreSQL repository Search methods now capture WithTxn errors. New tests use a failing database connector to verify transaction-start failures are returned.

Changes

Transaction error propagation

Layer / File(s) Summary
Capture transaction-wrapper errors
internal/store/postgres/*_repository.go
Four repository Search methods now retain WithTxn errors for their existing post-transaction checks.
Test transaction-start failures
internal/store/postgres/fakes_test.go, internal/store/postgres/*_repository_test.go
A failing connector and four repository tests verify that Search returns an error when transactions cannot start.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: rohilsurana

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

coveralls commented Jul 17, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29895848635

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.3%) to 46.4%

Details

  • Coverage increased (+0.3%) from the base build.
  • Patch coverage: 4 of 4 lines across 4 files are fully covered (100%).
  • 315 coverage regressions across 8 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

315 previously-covered lines in 8 files lost coverage.

File Lines Losing Coverage Coverage
core/membership/service.go 171 81.9%
internal/bootstrap/schema/schema.go 52 16.67%
internal/reconcile/permission_reconciler.go 22 75.26%
internal/reconcile/role_reconciler.go 22 82.91%
internal/reconcile/platformuser_reconciler.go 18 82.95%
internal/reconcile/preference_reconciler.go 17 77.42%
internal/reconcile/reconcile.go 11 86.81%
internal/reconcile/platformuser.go 2 97.98%

Coverage Stats

Coverage Status
Relevant Lines: 38463
Covered Lines: 17847
Line Coverage: 46.4%
Coverage Strength: 13.38 hits per line

💛 - Coveralls

A canceled context makes the transaction begin fail. Each Search method
must return that error instead of an empty result.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… files

Each repository test file gets a Search case using a client whose
connections always fail, so no database container is needed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread internal/store/postgres/org_billing_repository_test.go Outdated
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a7770ac2-b393-4c89-855f-cfae34c0a1b0

📥 Commits

Reviewing files that changed from the base of the PR and between 189c72b and 9c6bba8.

📒 Files selected for processing (5)
  • internal/store/postgres/fakes_test.go
  • internal/store/postgres/org_billing_repository_test.go
  • internal/store/postgres/org_projects_repository_test.go
  • internal/store/postgres/org_users_repository_test.go
  • internal/store/postgres/project_users_repository_test.go

Comment thread internal/store/postgres/fakes_test.go Outdated
Comment thread internal/store/postgres/org_billing_repository_test.go
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants