Skip to content
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

Fail when null is in a list of values in a query by attribute values #4120

Closed
danielvillalbamota opened this issue May 12, 2022 · 6 comments
Closed
Labels
Milestone

Comments

@danielvillalbamota
Copy link
Collaborator

Bug description
A clear and concise description of what the bug is. Please do not forget to add:

Having entities where for some of them have a specific attr, e.g. municipality with value null, a query by a list of values of this attributes gets an error.

How to reproduce it
Steps to reproduce the behavior (as an example)

  1. Create an entity this way:

    curl -iX POST 'http://localhost:1026/v2/entities' \
    -H 'Content-Type: application/json' \
    -d '
    {
        "id": "Bug:007",
        "type": "bug",
        "status": {
            "type": "Text",
            "value": "fixed"
        },
        "municipality": {
            "value": null,
            "type": "Text"
        }  
    }'
  2. When make the following query:

curl --location --request GET 'http://host:1026/v2/entities?q=municipality:null,alcobendas' \
--header 'Fiware-Service: service' \
--header 'Fiware-ServicePath: /subservice' \
  1. See error in the request response
400 Bad Request
{
    "error": "BadRequest",
    "description": "invalid JSON value type in list"
}
  1. When the query is just the null value the answer is correct
curl --location --request GET 'http://host:1026/v2/entities?q=municipality:null' \
--header 'Fiware-Service: service' \
--header 'Fiware-ServicePath: /subservice' \
--header 'X-Auth-Token: ...

Response:
200 OK

[
    ...,
    {
        "id": "Bug:007",
        "type": "bug",
        "municipality": {
            "type": "Text",
            "value": null,
            "metadata": {}
        },
        "status": {
            "type": "Text",
            "value": "fixed",
            "metadata": {}
        }
    }
]

Expected behavior

To be able to retrieve both set of entities, the ones with the municipality=alcobendas and the others with municipality=null

Additional information

NA

@fgalan fgalan added this to the 3.7.0 milestone May 12, 2022
@fgalan
Copy link
Member

fgalan commented May 17, 2022

Looking in StringFilter.h:

typedef enum StringFilterValueType
{
  ...
  SfvtNumberList,
  SfvtDateList,
  SfvtStringList
} StringFilterValueType;

So it seems our internal data structures are not though for mixing different types (string and null in this case) but let me think if I can come with some creative solution for this :)

@fgalan
Copy link
Member

fgalan commented May 17, 2022

We will use a new bool flag named nullInList to mark the existence of null within a list. Not a very smart solution, but it'll work.

@fgalan
Copy link
Member

fgalan commented May 17, 2022

PR #4123

@danielvillalbamota
Copy link
Collaborator Author

It seems when null is in the list of values, the CB retrieve entities without the filtered attribute (municipality), but what is expected are the entities with explicit null in the value as when just one value null is used (not a list).

@fgalan
Copy link
Member

fgalan commented May 18, 2022

It seems when null is in the list of values, the CB retrieve entities without the filtered attribute (municipality), but what is expected are the entities with explicit null in the value as when just one value null is used (not a list).

Fixed by PR #4127

@danielvillalbamota
Copy link
Collaborator Author

It works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants