diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 9fb1f84c8f..2c1ad6c507 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -4471,7 +4471,9 @@ unsigned int processContextElement responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE); } - if (updateCoverageP != NULL) + // The following check makes sense only when there are at least one attribute in the request + // (e.g. not for entity deletion, which doesn't include attributes) + if ((updateCoverageP != NULL) && (eP->attributeVector.size() > 0)) { if ((action == ActionTypeUpdate) || (action == ActionTypeDelete)) { diff --git a/test/functionalTest/cases/3499_partial_update_response/batch_delete_removing_attrs_and_entity_in_same_request.test b/test/functionalTest/cases/3499_partial_update_response/batch_delete_removing_attrs_and_entity_in_same_request.test new file mode 100644 index 0000000000..7f81f26734 --- /dev/null +++ b/test/functionalTest/cases/3499_partial_update_response/batch_delete_removing_attrs_and_entity_in_same_request.test @@ -0,0 +1,110 @@ +# Copyright 2023 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Removing attributes and etity itself in same entity batch delete + +--SHELL-INIT-- +dbInit CB +brokerStart CB + +--SHELL-- + +# +# 01. Create entities room1 and room2 +# 02. Delete room1 (temperature), room2 (temperature), room1 (entity itself), room2 (entity itself), get 204 +# + +echo "01. Create entities room1 and room2" +echo "===================================" +payload='{ + "entities": [ + { + "type": "house", + "id": "room1", + "temperature": 34 + }, + { + "type": "home", + "id": "room2", + "temperature": 44 + } + ], + "actionType": "append" +}' +orionCurl --url /v2/op/update?options=keyValues --payload "$payload" +echo +echo + + +echo "02. Delete room1 (temperature), room2 (temperature), room1 (entity itself), room2 (entity itself), get 204" +echo "==========================================================================================================" +payload='{ + "entities": [ + { + "type": "house", + "id": "room1", + "temperature": 34 + }, + { + "type": "home", + "id": "room2", + "temperature": 44 + }, + { + "type": "house", + "id": "room1" + }, + { + "type": "home", + "id": "room2" + } + ], + "actionType": "delete" +}' +orionCurl --url /v2/op/update?options=keyValues --payload "$payload" +echo +echo + + + + +--REGEXPECT-- +01. Create entities room1 and room2 +=================================== +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +02. Delete room1 (temperature), room2 (temperature), room1 (entity itself), room2 (entity itself), get 204 +========================================================================================================== +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +--TEARDOWN-- +brokerStop CB +dbDrop CB \ No newline at end of file