这是indexloc提供的服务,不要输入任何密码
Skip to content

Avoid (incorrectly) deserializing already serialized v2 query response #27

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

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

dmoverton
Copy link
Contributor

@dmoverton dmoverton commented Apr 4, 2024

Avoid deserializing the serialized query response back into a v2 QueryReponse. This was broken because the deserializer does not have enough information to differentiate between object-valued fields and relations.

The reason we were deserializing the v2 response was so that we could convert it into a v3 QueryResponse. Fortunately, it is not necessary to do this. The v2 and v3 query responses have almost the same JSON representation. The only difference is that in v3 the response is returned within a (singleton) array.

Therefore, rather than fully deserializing to a v2 QueryResponse, all we need to do is deserialize to a JSON value, wrap it in an array and serialize again.

@dmoverton dmoverton self-assigned this Apr 4, 2024
@dmoverton dmoverton marked this pull request as draft April 4, 2024 01:48
@dmoverton dmoverton requested a review from hallettj April 4, 2024 10:19
@dmoverton dmoverton marked this pull request as ready for review April 4, 2024 10:19
Copy link
Collaborator

@hallettj hallettj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but we'll have to rewrite this shortly to serialize each value using bson_to_json. If we have to do either that before converting to Value, or convert the extended JSON from each value back to BSON to then translate to simple JSON.

@dmoverton dmoverton merged commit a9886fe into main Apr 4, 2024
@dmoverton dmoverton deleted the dmoverton/fix/query_response branch April 4, 2024 21:49
hallettj added a commit that referenced this pull request Apr 12, 2024
The change in #27 fixed serializing query responses with object values, but serializing foreach responses stopped working. This PR switches back to roughly the logic in which foreach responses were working, and fixes the issue with object values in a different way.

This is a quick patch - we still need to rework response serialization to use `bson_to_json` translation. That will require using the query request to direct response serialization which should make everything more robust.

I removed the use of `JsonResponse` in this PR because it serves no purpose for this connector. `JsonResponse` is useful for connectors that get a JSON response from the database, which the connector can pass through without processing. But as far as we can determine MongoDB always sends BSON so to get JSON output we're stuck doing response processing in the connector.

There's also a fix in here to avoid using `$literal` expression escaping in a context where expressions are not evaluated.

Fixes https://hasurahq.atlassian.net/browse/MDB-19

---------

Co-authored-by: Brandon Martin <brandon@codedmart.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants