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

ngsild post entity ignore unset properties #385

Open
djs0109 opened this issue Jan 31, 2025 · 3 comments
Open

ngsild post entity ignore unset properties #385

djs0109 opened this issue Jan 31, 2025 · 3 comments
Assignees
Labels
bug Something isn't working NGSI-LD

Comments

@djs0109
Copy link
Contributor

djs0109 commented Jan 31, 2025

Describe the bug
Current ngsild post entity will ignore all unset and default varaiables when posting the entity

To Reproduce

from pydantic import BaseModel
from pydantic.fields import Field, FieldInfo
from filip.models import FiwareLDHeader
from filip.models.ngsi_ld.context import ContextLDEntityKeyValues
from filip.clients.ngsi_ld.cb import ContextBrokerLDClient

class OutsideAirTemperatureSensor(
    BaseModel):
    """
    https://brickschema.org/schema/Brick#Outside_Air_Temperature_Sensor
    """
    temperature: float = Field(
        default=20.0,
        description="brick:Quantity, measure temperature in degree Celsius"
    )

class OutsideAirTemperatureSensorFIWARE(OutsideAirTemperatureSensor, ContextLDEntityKeyValues):
    type: str = FieldInfo.merge_field_infos(
        # Field info of the general FIWARE data model in FiLiP
        ContextLDEntityKeyValues.model_fields["type"],
        default="OutsideAirTemperatureSensor"
    )

CB_URL = "http://localhost:1027"
NGSILD_TENANT = 'filip'  # NGSI Tennant (equivalant to FIWARE service in NGSI v2)
SERVICE_PATH = '/'  # FIWARE-Servicepath
fiware_header = FiwareLDHeader(ngsild_tenant=NGSILD_TENANT)
cb_client = ContextBrokerLDClient(url=CB_URL, fiware_header=fiware_header)

t_sen = OutsideAirTemperatureSensorFIWARE(id="OutsideAirTemperatureSensor:01")

cb_client.post_entity(entity=t_sen, update=True)

Expected behavior
The entity above can be created

@djs0109 djs0109 added bug Something isn't working NGSI-LD labels Jan 31, 2025
@djs0109 djs0109 changed the title ngsild post entity ignore unset entity ngsild post entity ignore unset properties Feb 4, 2025
Copy link

github-actions bot commented Feb 4, 2025

Branch 385-ngsild-post-entity-ignore-unset-properties created!

@djs0109
Copy link
Contributor Author

djs0109 commented Feb 4, 2025

@SystemsPurge the exclude_unset, exclude_default can be removed. I am not sure, whether we should also remove exclude_none.

json=entity.model_dump(
exclude_unset=True, exclude_defaults=True, exclude_none=True
),

data=json.dumps(
update.model_dump(
by_alias=True,
exclude_unset=True,
exclude_none=True,
).get("entities")

@SystemsPurge
Copy link
Collaborator

@djs0109 I will test all of them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working NGSI-LD
Projects
None yet
Development

No branches or pull requests

2 participants