Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSGO-47 Enable Session.ExecuteBatchCAS() to return underlying scan errors #1860

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Retry policy now takes into account query idempotency (CASSGO-27)
- Don't return error to caller with RetryType Ignore (CASSGO-28)
- Enable Session.ExecuteBatchCAS() to return underlying scan errors (CASSGO-47)

## [1.7.0] - 2024-09-23

Expand Down
12 changes: 12 additions & 0 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,18 @@ func TestCAS(t *testing.T) {
t.Fatal("scan:", err)
}
}

notAppliedBatch := session.Batch(LoggedBatch)
notAppliedBatch.Query("INSERT INTO cas_table (title, revid, last_modified) VALUES (?, ?, ?) IF NOT EXISTS", title, revid, modified)
// This record is already inserted into the table so C* should return [applied] = false and previous record state,
// but we didn't provide any destination variables to handle result, so it should return an error
if applied, _, err := session.ExecuteBatchCAS(notAppliedBatch); err == nil {
t.Fatal("should fail because of lacking of destination variables")
} else if applied {
t.Fatalf("insert should have not been applied")
} else if !strings.Contains(err.Error(), "gocql: not enough columns to scan into") {
t.Fatalf("should have failed because of invalid destination variables, but failed because: %v", err)
}
}

func TestDurationType(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ func (s *Session) ExecuteBatch(batch *Batch) error {
// ExecuteBatchCAS executes a batch operation and returns true if successful and
// an iterator (to scan additional rows if more than one conditional statement)
// was sent.
// Further scans on the interator must also remember to include
// Further scans on the iterator must also remember to include
// the applied boolean as the first argument to *Iter.Scan
func (s *Session) ExecuteBatchCAS(batch *Batch, dest ...interface{}) (applied bool, iter *Iter, err error) {
iter = s.executeBatch(batch)
Expand All @@ -785,7 +785,7 @@ func (s *Session) ExecuteBatchCAS(batch *Batch, dest ...interface{}) (applied bo
iter.Scan(&applied)
}

return applied, iter, nil
return applied, iter, iter.err
}

// MapExecuteBatchCAS executes a batch operation much like ExecuteBatchCAS,
Expand Down