mindlesscloud opened a new pull request, #4998:
URL: https://github.com/apache/incubator-devlake/pull/4998
### Summary
Before going any further, let's take a look at an example.
```go
var f struct {
I int `json:"i"`
A *string `json:"a"`
}
blob1 := `{"i": 42, "a": "hello"}`
json.Unmarshal([]byte(blob1), &f)
blob2 := `{"i": 42}`
json.Unmarshal([]byte(blob2), &f)
fmt.Println(*f.A)
```
The output of this piece of code would be "hello", because the `blob2` has
no "a" key, the field `f.A` would keep the value set at the last time.
The `ExtractExistRawData` function in the `GraphqlCollector` suffers from
the same issue. During each iteration of the loop, the same query object is
being populated by a call to `json.Unmarshal`, causing the previous field
values to persist. To fix this issue, we propose creating a new query object
during each iteration of the loop.
Here's the relevant code:
```go
query, variables, _ := collector.args.BuildQuery(nil)
for cursor.Next() {
err = db.Fetch(cursor, row)
err = errors.Convert(json.Unmarshal(row.Data, &query))
}
```
### Does this close any open issues?
Closes #4988
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]