fix: TT-16778 GORM v2 table sharding bug#949
Conversation
|
This PR fixes a critical bug in SQL-based pumps where enabling table sharding resulted in data being written to the default table instead of the correct date-sharded table. This was caused by an incorrect method order in GORM, where Additionally, a separate issue causing CI failures when Files Changed Analysis
Architecture & Impact Assessment
sequenceDiagram
participant Pump
participant GORM
participant Database
Note over Pump, GORM: Before Fix (Incorrect Order)
Pump->>GORM: .Table("sharded_table_20260311")
GORM->>GORM: Sets target table
Pump->>GORM: .WithContext(ctx)
GORM->>GORM: Resets target table to default!
Pump->>GORM: .Create(...)
GORM->>Database: INSERT INTO "default_analytics_table"
Note over Pump, GORM: After Fix (Correct Order)
Pump->>GORM: .WithContext(ctx)
GORM->>GORM: Sets context
Pump->>GORM: .Table("sharded_table_20260311")
GORM->>GORM: Sets target table
Pump->>GORM: .Create(...)
GORM->>Database: INSERT INTO "sharded_table_20260311"
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-03-11T19:21:55.674Z | Triggered by: pr_updated | Commit: cfadd4b 💡 TIP: You can chat with Visor using |
✅ Security Check PassedNo security issues found – changes LGTM. Architecture Issues (2)
✅ Performance Check PassedNo performance issues found – changes LGTM. ✅ Security Check PassedNo security issues found – changes LGTM. \n\nArchitecture Issues (2)
Quality Issues (3)
Powered by Visor from Probelabs Last updated: 2026-03-11T19:21:45.417Z | Triggered by: pr_updated | Commit: cfadd4b 💡 TIP: You can chat with Visor using |
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
|


This PR supersedes and closes #948.
Problem / Task
In
SQLAggregatePump,SQLPump, andGraphSQLPump, the.WithContext(ctx)call drops the previously applied.Table(table)modifier. This causes theINSERTstatement to target the default table instead of the sharded table.This PR also fixes a CI issue where tests would fail with an
empty slice founderror ifBatchSizewas set to 0 in the configuration. A fallback to the default batch size has been added to the batching loops.Changes
.Table(table)modifier is now chained after.WithContext(ctx)to ensure the correct table is targeted.BatchSizeinpumps/sql_aggregate.go,pumps/sql.go, andpumps/graph_sql.goto prevent errors with empty slices.Testing
Added unit tests to verify the fix.
Requested by: @U3P2L4XNE | Trace: cc2d9c4a03c8142a19785badffab0fca
Generated with Tyk AI Assistant
Ticket Details
TT-16778
Generated at: 2026-03-11 19:20:04