-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Unable to marshal response error #2662
Comments
So it looks like the escaping of The mutation succeeds because it is encoded (e.g. via JSON.stringify(obj)) - but it seems like that escaping is being lost somewhere on ingestion into Dgraph. |
I am experiencing, I guess, the same issue right now 🙂 In my case it's the string "KHL\u0000" |
This has to do with unicode optimizations done by Go. The escape sequence I'd suggest to add slash to those chars you know will be control chars and try again. e.g.,, |
any luck with this? I will close this issue, re-open if you think of any alternatives. |
@srfrog why is this being closed? The workaround is not desirable and is likely to catch a lot of people out. I would have thought it should only be used while a fix is pending? At the moment, it's not documented anywhere, and it causes the entire query to be unreturnable without any clear error message. I really think this should be fixed! |
The JSON spec states that control characters are not part of a string. You need to double-escape them with The alternative I was referring is that we would need to find a way to insert slashes for escape sequences without breaking normal unicode escapes. I think that you would know the data needs the slashes and add another pass to escape them instead of Dgraph doing this auto. |
I'm able to run this code, with no issues: https://play.golang.org/p/cUKMcr5UqC- It looks like an issue specific to Dgraph, not Go.
|
That example is not accurate. This is actually what is going on: https://play.golang.org/p/qaUXuiAcP83
For all our responses we are returning a blind map using interface{}, we must do that because we expect different values at various levels (think of the query). So Alternatives:
|
The behavior here (replacing \u00 with \x) is due to the fix for this issue: #1508 We use |
I made a small commit ae1d9f3 We have to use @niemeyer: Do you have any ideas regarding this particular issue? |
I most likely don't understand the actual issue, as my reading from the above would indicate that the bug is that Dgraph is sending broken JSON on the wire by putting something in a json.RawMessage that is not in fact valid JSON. If that was the case, the straightforward solution would be of course to not do that, and make sure that anything sent through the wire to be consumed as JSON is in fact JSON. That understanding comes from the two exchanges above where you said that this works but then the reply was that this doesn't. Yes, it doesn't work and it shouldn't, since what's going into RawMessage seems bogus? But again, I'm sure you already had that much figured out. So what am I missing? |
Can you look at my last two comments? It includes a link to the issue you created some time ago, and a link to go playground which shows how it happens. |
That issue is about a different file format which takes data in a different representation. The fix done there, which makes Dgraph read the format properly and store data in raw form, seems correct to me. The problem here, as far as I could perceive given the above exchanges, is that some data in non-JSON form is being embedded into a JSON document, and as expected that is breaking down. Go's quoting and JSON quoting are not interchangeable. IOW, this is a bug if the data if the data is being embedded in a JSON result with RawMessage:
|
To clarify, this is not a RawMessage issue. We have our own JSON encoder which we use to generate JSON response, which we were then encapsulating in RawMessage. There was no need for that. In fact, I removed the RawMessage usage in my last change. The issue is around this JSON string creation. So, we store data in the raw format, which is correct. Now, when we need to create the JSON, we have to put quotes around the data to create JSON key-value ( Line 148 in ae1d9f3
In essence, we use |
Yeah, that has the same effect, and thus is certainly a bug. |
We should be correctly dealing with JSON strings now. You can build Dgraph from master and try it out. |
If you suspect this could be a bug, follow the template.
What version of Dgraph are you using?
v1.0.9 (latest)
Have you tried reproducing the issue with latest release?
Yes
What is the hardware spec (RAM, OS)?
MacOS + Docker (4GB RAM for Docker) - --lru_mb=1024
Steps to reproduce the issue (command/config used to run Dgraph).
Add the following mutation:
Then run the following query (replacing 0x1d788 for new uid):
Expected - return the log message that was set
Actual -
{"errors":[{"code":"Error","message":"Unable to marshal response"}],"data":null}
The text was updated successfully, but these errors were encountered: