You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Condition::default() creates an invalid condition that can't be used #205
I'm sure you are aware, but in the mean time you can oneoftheotherfunctions to create the desired condition.
Sure. In my case, the way it occurred is that I had a function that received a structure with optional fields, which I then converted into conditions that were passed to the Filter, e.g.:
So it was a compact, elegant implementation that I assumed would work (typically, if there is a Default implementation, it produces a structure that is valid and can be used), but later I discovered that the function fails in some cases and traced it back to that place in Qdrant that rejects None conditions.
After quick inspection - I'm afraid we cannot remove the Default implementation at this time because gRPC framework we use puts it there for us.
There are still several ways to mitigate it. For instance, instead of exposing the low-level "over-the-wire" representation of the Condition, one could expose a convenient high-level type to the user and only convert it to the low-level representations inside a library. This ensures that the client only interacts with a "safe" high-level API that prevents errors.
Alternatively, there is a "lazy solution", such as making the functions that accept Condition, such as Filter::all or other, to return an error if they receive an invalid condition. It would still be more efficient than letting the user to send an invalid request to the server, only to discover that it's not valid and gets rejected, i.e. we could spare that additional round-trip and return error immediately when we know upfront that the request is invalid and won't be processed anyway.
However, a better design would simply prevent creating "invalid" structures to avoid bugs and issues 🙂 And to be honest, the Condition type is almost perfect already - it provides lots of useful high-level functions, that's why I think that it just needs to either not have Default, or make Default return something that is valid. If its internal fields could be misused, they should also be made private. I.e. I think there is a simple way to fix the issue by just wrapping the internal 'over-the-wire' Condition into a newtype that prevents such things from happening.
Activity
timvisee commentedon Dec 23, 2024
Thanks!
I think we should remove the
Defaultimplementation onConditionto prevent misuse of this with provided functions.I'm sure you are aware, but in the mean time you can one of the other functions to create the desired condition.
timvisee commentedon Dec 23, 2024
After quick inspection - I'm afraid we cannot remove the
Defaultimplementation at this time because gRPC framework we use puts it there for us.It is implied by
::post::Message:rust-client/src/qdrant.rs
Line 5636 in 1707b92
daniel-abramov commentedon Dec 23, 2024
Sure. In my case, the way it occurred is that I had a function that received a structure with optional fields, which I then converted into conditions that were passed to the
Filter, e.g.:So it was a compact, elegant implementation that I assumed would work (typically, if there is a
Defaultimplementation, it produces a structure that is valid and can be used), but later I discovered that the function fails in some cases and traced it back to that place in Qdrant that rejectsNoneconditions.There are still several ways to mitigate it. For instance, instead of exposing the low-level "over-the-wire" representation of the
Condition, one could expose a convenient high-level type to the user and only convert it to the low-level representations inside a library. This ensures that the client only interacts with a "safe" high-level API that prevents errors.Alternatively, there is a "lazy solution", such as making the functions that accept
Condition, such asFilter::allor other, to return an error if they receive an invalid condition. It would still be more efficient than letting the user to send an invalid request to the server, only to discover that it's not valid and gets rejected, i.e. we could spare that additional round-trip and return error immediately when we know upfront that the request is invalid and won't be processed anyway.However, a better design would simply prevent creating "invalid" structures to avoid bugs and issues 🙂 And to be honest, the
Conditiontype is almost perfect already - it provides lots of useful high-level functions, that's why I think that it just needs to either not haveDefault, or makeDefaultreturn something that is valid. If its internal fields could be misused, they should also be made private. I.e. I think there is a simple way to fix the issue by just wrapping the internal 'over-the-wire'Conditioninto a newtype that prevents such things from happening.timvisee commentedon Dec 23, 2024
Yes, I totally agree. I understand that it's easy to construct this 'broken' variant the way you describe. Thanks for your suggestions.
I implemented a quick fix to filter out empty conditions, resolving this issue: qdrant/qdrant#5690
timvisee commentedon Jan 8, 2025
We've just released Qdrant 1.12.6 which includes the patch for this problem. Thank again for bringing this to our attention!