telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 265 forks source link

[BUG] In create request is possible to create an entity with N equal attributes #1444

Closed iariasleon closed 8 years ago

iariasleon commented 8 years ago

Create request:

 http://qa-orion-fe-01:1026/v2/entities
Content-Type: application/json
Fiware-Service: test_service_path
Fiware-ServicePath:/test
{"type":"house", "temperature": {"type": "celcius", "value": "34"}, "temperature": {"type": "celcius", "value": "49"},"id": "room7"}

Create response:

Status 201 Created 

Doc in mongo:

{ "_id" : { "id" : "room7", "type" : "house", "servicePath" : "/test" }, "attrNames" : [ "temperature", "temperature" ], "attrs" : { "temperature" : { "type" : "celcius", "creDate" : 1446122837, "modDate" : 1446122837, "value" : "34" }, "temperature" : { "type" : "celcius", "creDate" : 1446122837, "modDate" : 1446122837, "value" : "34" } }, "creDate" : 1446122837, "modDate" : 1446122837 }
iariasleon commented 8 years ago

In 0.26.0 the error description is not descriptive:

{
error: "InvalidModification"
description: "Entity already exists"
}

Suggested:

{
error: "InvalidModification"
description: "duplicated attribute"
}
fgalan commented 8 years ago

Note that the corresponding error in NGSI is much more clear (see https://github.com/telefonicaid/fiware-orion/blob/develop/test/functionalTest/cases/0908_update_duplicated_attributes/dup_attrs_avoid_db_error.test#L135). Thus, probably the point to fix is the NGSIv1 to NGSIv2 error transformation done in the corresponding serviceRoutinev2.

fgalan commented 8 years ago

Fixed in PR https://github.com/telefonicaid/fiware-orion/pull/1598. @iariasleon please have a look and close it if you find it ok.

iariasleon commented 8 years ago

LGTM

Status: 422 Unprocessable Entity
{
   "error": "InvalidModification",
   "description": "duplicated attribute /temperature/"
}