fix: propagate ctx on query error (#9421)
diff --git a/datastore/query.go b/datastore/query.go
index 0bfe901..ad5fb29 100644
--- a/datastore/query.go
+++ b/datastore/query.go
@@ -726,7 +726,7 @@
// run runs the given query in the given context.
func (c *Client) run(ctx context.Context, q *Query) *Iterator {
if q.err != nil {
- return &Iterator{err: q.err}
+ return &Iterator{ctx: ctx, err: q.err}
}
t := &Iterator{
ctx: ctx,
diff --git a/datastore/query_test.go b/datastore/query_test.go
index 6d58765..879da29af 100644
--- a/datastore/query_test.go
+++ b/datastore/query_test.go
@@ -796,6 +796,35 @@
}
}
+func TestRunErr(t *testing.T) {
+ client := &Client{
+ client: &fakeClient{
+ queryFn: func(req *pb.RunQueryRequest) (*pb.RunQueryResponse, error) {
+ fmt.Printf("received next request")
+ return fakeRunQuery(req)
+ },
+ },
+ }
+
+ type Gopher struct {
+ A int
+ }
+
+ ctx := context.Background()
+ q := NewQuery("Gopher").Filter("", 2)
+ it := client.Run(ctx, q)
+
+ var g1 Gopher
+ it.Next(&g1)
+
+ defer func() {
+ if r := recover(); r != nil {
+ t.Errorf("Cursor panic")
+ }
+ }()
+ it.Cursor()
+}
+
func TestAggregationQuery(t *testing.T) {
client := &Client{
client: &fakeClient{