-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Search][BUG] Wrong dynamic for empty array of string #8699
Comments
The applied workaround is
|
This behavior is by design. In the dynamic case, the SDK has no information about what data type is contained within the collection. In previous versions, the only collection type that was supported was If your application is aware of the types of these fields, then I'd recommend using your own model type as this will guide deserialization and always result in the correct .NET type (assuming you've defined your model type correctly). We do not plan to change this behavior, especially since there is a workaround, so I'm closing this issue. |
"by design", really? Why you are constraining a user to define a type of a collection to then check the type when the user store something but, in the response, you are returning an aubergine? In OSS "by design" is not a magic word to avoid bug fix. BTW make what your professionalism say you. |
@fabiomaulo My apologies, I should not have closed the issue without further discussion. I've re-opened it until we can reach a consensus.
The test for this case is here: Line 363 in 0ad1054
There are other tests in the same file that pin other behaviors that similarly aren't ideal and are caused by the lack of type information. This behavior is documented here.
I will explain in more detail why this doesn't work the way you expect. I will also list the alternatives we considered. In the .NET SDK, there are two sets of data retrieval methods: Those that take a generic type parameter, and those that don't. Both sets of methods use JSON.NET to deserialize the JSON responses returned by Azure Cognitive Search. In the case of the generically-typed methods, the type you pass is supposed to correspond to your index definition, and it's used to deserialize each JSON property in the response to its correct type. However, for the methods that don't take a type parameter, there is no type information available to determine the actual type of the data in the response. This is because the REST API does not return fully self-describing responses. For this reason, the implementation currently has to make some assumptions. For empty collections, the assumption is that it's less surprising to receive This is not ideal behavior, so we considered some ways to fix it:
So while it's possible to fix this, none of the fixes are easy and they all have their own drawbacks. Also, workarounds are possible. If you have an idea for fixing this that is simpler and more robust than what I've mentioned, we would be happy to consider it. |
Hi Bruce. The problem here is something I saw even in others SDKs (IIRC docDb) and, IMO, is a conceptual error: don't touch the dynamic result ;). You give us a way to work with strongly-typed DTO/entities and with dynamic-objects;
In practice: don't try to transform the I'll happy to read your opinion about P.D. just something to transform the dynamic without know what it contains: https://gist.github.com/fabiomaulo/d03700a8ea1ec99d8725058cc67b10a7 |
@fabiomaulo Thanks for the explanation -- this makes sense now. The fact that you can convert an empty This feedback comes at a good time, because we're starting to think about the next generation of the .NET SDK. Several months ago, new Azure API Guidelines were announced, and we plan to re-engineer our .NET SDK to be compliant with these guidelines (although there is no timeline for this yet). One complicating factor is that JSON.NET is being deprecated in favor of the new In the meantime, I'll keep this issue open to track this scenario and I'll run it by the Azure API review board. Please don't expect any short-term updates though -- this is very much a long-term issue. |
Thanks. |
For |
We have support for this now. @Mohit-Chakraborty let's try and get a small sample written for this. |
We have an example of extracting properties by name and casting them to custom types here. |
Closing this issue. Please let us know if you need further assistance or want to continue the discussion. |
@Mohit-Chakraborty thanks I'll try it hopefully soon. We are in the process of converting all our prjs from net472+net22+net31 -> NET6 (obviously the problem are public-webs prjs). |
Since the |
Having two fields declared as
And in Azure correctly created
The search result returs an array of
string
when the array has some elements and an empty array ofobject
when the array is empty.The bug was found in version 10.1.0 actualizing from 3.x so... I don't know which is the exact version where the bug was introduced.
The text was updated successfully, but these errors were encountered: