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

get_entity_list should ignore bad entity if the validation is failing #374

Open
djs0109 opened this issue Jan 15, 2025 · 2 comments · May be fixed by #375
Open

get_entity_list should ignore bad entity if the validation is failing #374

djs0109 opened this issue Jan 15, 2025 · 2 comments · May be fixed by #375
Assignees
Labels
feature request Request a potential feature

Comments

@djs0109
Copy link
Contributor

djs0109 commented Jan 15, 2025

Filip will validate every entity in the returned list against 1) data value and type 2) unit specified as metadata. If any of this validation does not work, filip will abort and raise an error.

Expected behavior

Filip can give a warning, on what entity is failing the validation, and still return the rest valid entities.

To reproduce

import json
import requests
from filip.clients.ngsi_v2 import ContextBrokerClient
from filip.models.base import FiwareHeader
from filip.models.ngsi_v2 import ContextEntity
from filip.utils.cleanup import clear_context_broker

orion_url = "http://...:1026"

fiware_header = FiwareHeader(service="filip_374", service_path="/")
cbc = ContextBrokerClient(
    url=orion_url,
    fiware_header=fiware_header)
clear_context_broker(cb_client=cbc)

# Send bad entities to the Context Broker
entity_wrong_value_type = {
    "id": "test:weather_station_1",
    "type": "WeatherStation",
    "temperature": {"type": "Number", "value": "Error"}
}

entity_wrong_unit = {
    "id": "test:weather_station_2",
    "type": "WeatherStation",
    "temperature": {"type": "Number",
                    "value": 20,
                    "metadata":
                        {"unitCode":
                             {"type": "Text",
                              "value": "Error"}
                         }
                    }
}

headers = {
  'fiware-service': 'filip_374',
  'fiware-servicepath': '/',
  'Content-Type': 'application/json'
}

for entity in [entity_wrong_value_type, entity_wrong_unit]:
    payload = json.dumps(entity)
    url = f"{orion_url}/v2/entities"
    response = requests.request("POST", url, headers=headers, data=payload)
    print(response.text)

# send dummy valid entities to the Context Broker
entities_valid = [ContextEntity(id=f"test374:Entity:{i}", type="Test") for i in range(10)]
cbc.update(entities=entities_valid, action_type="append")

# TODO the bad entities will block the whole request
entities = cbc.get_entity_list()
Copy link

@djs0109
Copy link
Contributor Author

djs0109 commented Jan 21, 2025

The ignore validation feature should also be added to "delete" endpoint

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

Successfully merging a pull request may close this issue.

1 participant