-
-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Missing some IDs on insert. #192
Comments
After running some tests I have tracked this issue down to the code that decodes the database result. Basically the raw result from the database looks something like this: map[string]interface {}{"A":false, "B":41, "Id":"", "id":"f0d4bc93-048a-4383-8c99-15ef0218a067"} Because there are two "Id" fields I think that because of how Go randomly iterates through maps the driver randomly uses either "Id" or "id" when decoding into the type T struct {
Id string `gorethink:"id"`
A bool
B int
} |
Well, here is another bug, adding However, the driver ignores the Running the same query, as in inserting multiple documents with Temporary fix for this issue is to use |
The issue with the duplicate keys occurs because the DB doesnt return any kind of error response but instead puts the error in the response body. I think the only way of fixing this is to update the |
To avoid the issue of |
So I wasnt quite right with my first explanation, this issue is actually due to the Id field being overwritten due to http://golang.org/pkg/reflect/#Value.MapKeys returning the keys in an unspecified order. I will update the driver to sort the result of MapKeys which should at least make the behaviour more predictable. |
Merged a fix to |
How does this effect performance?
|
I would hope that it shouldnt affect performance too much, however since I am relying on reflection it could be potentially quite expensive. Have you noticed any issues since the change? |
I have not updated yet and was kinda hoping I could wait for v1.0 but happy to try this fix. My concern is that sorting makes this O(n) where N is the size of struct, this might not be much but it adds up specially when fast writes are necessary where batch insert is not possible.
|
FWIW, I would support requiring annotated structs to handle this. The alternative is always sorting all fields on the off chance that a user has used case-sensitive overlapping keys. Since using JSON structured like that sounds like a royal pain ( Maybe the path forward is to document how golang struct fields may lose information, and that cautious users should annotate their structs? |
👍 for documentation over compromising on efficiency. |
Agreed, Ill revert the change and add some more documentation. |
Running the following code:
Will give you, some Ids missing:
While running
r.db('test').table('ts').changes()("new_val")
in Data Explorer shows a correct id per document.The text was updated successfully, but these errors were encountered: