Skip to content

Commit

Permalink
Merge pull request #16 from Recidiviz/dan/invalid-query
Browse files Browse the repository at this point in the history
Return `invalidQuery` to avoid Python SDK's default 10-minute retry for `internalError` responses
  • Loading branch information
ohaibbq committed May 22, 2024
2 parents c15346f + e151625 commit c27caf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ func (h *jobsInsertHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
job: &job,
})
if err != nil {
errorResponse(ctx, w, errJobInternalError(err.Error()))
errorResponse(ctx, w, errInvalidQuery(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down Expand Up @@ -1758,7 +1758,7 @@ func (h *jobsQueryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
useInt64Timestamp: isFormatOptionsUseInt64Timestamp(r),
})
if err != nil {
errorResponse(ctx, w, errJobInternalError(err.Error()))
errorResponse(ctx, w, errInvalidQuery(err.Error()))
return
}
encodeResponse(ctx, w, res)
Expand Down
12 changes: 12 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ func TestSimpleQuery(t *testing.T) {
t.Fatal("Failed to query null ARRAY")
}
})

// Regression test for goccy/bigquery-emulator#316
t.Run("invalid query", func(t *testing.T) {
query := client.Query("SELECT!;")
_, err := query.Read(ctx)
if err == nil {
t.Fatal("Expected error, but got nil")
}
if !strings.HasSuffix(err.Error(), "invalidQuery") {
t.Fatal("expected invalid query")
}
})
}

func TestDataset(t *testing.T) {
Expand Down

0 comments on commit c27caf6

Please sign in to comment.