fix: only check zero affected rows on first provisioning query#117
fix: only check zero affected rows on first provisioning query#117c1-dev-bot[bot] wants to merge 1 commit intomainfrom
Conversation
The rowsAffected == 0 check in RunProvisioningQueries breaks multi-query revoke configs. When a secondary query legitimately affects 0 rows (e.g., a conditional UPDATE that only fires when certain conditions are met), the check triggers ErrQueryAffectedZeroRows, rolling back the entire transaction including the successful first query. Revoke() then catches this as GrantAlreadyRevoked and returns success — silently discarding the work. Fix: only apply the zero-rows check to the first query (index 0), which represents the primary operation. Zero rows on the first query still correctly signals "already granted/revoked." Secondary queries are allowed to affect 0 rows without triggering rollback. Fixes: CXH-1341
|
Claude finished @c1-dev-bot[bot]'s task in 1m 22s —— View job PR Review: fix: only check zero affected rows on first provisioning query
SummaryClean, minimal, well-targeted fix. The change is correct and the PR description explains the problem clearly. ReviewThe fix is sound. The Observations:
Verdict: Approve with minor suggestions. The core logic change is correct and well-scoped. |
| if i == 0 && rowsAffected == 0 { | ||
| return ErrQueryAffectedZeroRows | ||
| } |
There was a problem hiding this comment.
nit: Consider adding a debug log when a secondary query affects 0 rows, so operators have visibility into when this happens during troubleshooting. Something like:
| if i == 0 && rowsAffected == 0 { | |
| return ErrQueryAffectedZeroRows | |
| } | |
| if i == 0 && rowsAffected == 0 { | |
| return ErrQueryAffectedZeroRows | |
| } | |
| if rowsAffected == 0 { | |
| l.Debug("secondary query affected 0 rows", zap.Int("query_index", i), zap.String("query", q)) | |
| } |
Not blocking — the current behavior is correct. But silently continuing on 0-row secondary queries could make debugging harder if a config mistake causes a secondary query to be a no-op when it shouldn't be.
Summary
rowsAffected == 0check inRunProvisioningQueriesProblem
The
rowsAffected == 0check (introduced in v0.5.2, commit d80deff) applies to all queries in a multi-query provisioning block. When a revoke config has a conditional second query (e.g., UPDATE user deactivation that only fires on last role removal), the second query may legitimately affect 0 rows. This triggersErrQueryAffectedZeroRows, which:Revoke()asGrantAlreadyRevokedFix
Change the loop in
RunProvisioningQueriesfromfor _, q := range queriestofor i, q := range queries, and gate the zero-rows check withi == 0. This preserves the useful "already granted/revoked" detection for the primary query while allowing secondary queries to affect 0 rows.Test plan
ErrQueryAffectedZeroRowswhen 0 rows affectedrowsAffected > 1check still applies to all queriesFixes: CXH-1341
Automated PR Notice
This PR was automatically created by c1-dev-bot as a potential implementation.
This code requires: