-
Notifications
You must be signed in to change notification settings - Fork 302
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
Query returns same result even when different parameter value given #1071
Comments
Really weird. Will it become reproducible if you put the relevant code in a loop? |
I think you have to put this code in a loop (query part) to reproduce issue. In my project this happens very rarely but usually when two requests are executed in rapid succession. Here are log lines produced by my application when this happens:
And here how code that logs this looks like: { it:Map.Entry<String, Any> ->
val existing: KAEntry? = byKeyQuery.setParameter("key", it.key).findUnique()
logd { "setPropValue existing.key = ${existing?.key} [${existing?.id}] for ${it.key}" }
// do some other stuff
} You can see that |
Thanks for the additional details. However, I failed to reproduce this. I tested using a local unit test on Windows and an instrumentation test on an Android 12 emulator. Used test code like: @Entity
public class Customer {
@Id long id;
@Unique String name;
}
customerBox.put(new Customer(0, "first"));
customerBox.put(new Customer(0, "second"));
try (Query<Customer> query = customerBox.query()
.equal(Customer_.name, "", QueryBuilder.StringOrder.CASE_SENSITIVE)
.parameterAlias("key")
.build()) {
for (int i = 0; i < 10000; i++) {
query.setParameter("key", "first");
assertEquals("first", getUniqueNotNull(query).getName());
query.setParameter("key", "second");
assertEquals("second", getUniqueNotNull(query).getName());
}
} If you are happy to spend the time, could you provide a small example project that reproduces this issue? |
What |
I think that this is a race condition during call to |
@AngryGami Agreed.
|
While this is the way it is (i.e. non-safe to call |
If it's not a hotspot, it is usually fine. |
https://docs.objectbox.io/queries#reusing-queries-and-parameters now has a note about re-using queries across multiple threads. Also with the new Let us know if there are issues! |
Great. But we need it in GO SDK. |
Describe the bug
Despite explicit setting different parameter value subsequent query executions return same result sometimes (if made quickly enough, or maybe two different parameter values have same hash?)
Basic info (please complete the following information):
To Reproduce
See code section
Expected behavior
For different parameters values results must be different.
Code
Additional context
I assumed that this is issue with reuse of byKeyQuery object and instead of reusing it I create new query every time. I'm not 100% sure yet if this helped since this issue is very sporadic, but I'll know if it reappears.
The text was updated successfully, but these errors were encountered: