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

Fix: Extra information about partial updates in responses #3499 #4097

Closed
wants to merge 4 commits into from

Conversation

Anjali-NEC
Copy link
Contributor

Fix issue #3499

@Anjali-NEC
Copy link
Contributor Author

Hi @fgalan sir,

Please review my updated commit and if it is ok then please merge it into master.

@fgalan
Copy link
Member

fgalan commented May 3, 2022

Looking to the .test that has been modified, it seems you have added the extra information to response to GET /v2/entities/{id}/attrs/{name} and GET /v2/entities/{id}/attrs/{name}/value. However, note that is not the purpose of the issue. The issue refers to partial updates not to queries.

I'd suggest to model the case in a .test, roughly this way:

  1. Create entity E with attribute A=1
  2. Do a strict update E A=10 B=20 C=30, get error about entity does not have attribute B and C
  3. Get E, check A=10
  4. Do a strict update E A=100 B=200, get error about entity does not have attribute B
  5. Get E, check A=100

and use that .test to guide your implementation

@fgalan
Copy link
Member

fgalan commented May 3, 2022

Looking to the .test that has been modified, it seems you have added the extra information to response to GET /v2/entities/{id}/attrs/{name} and GET /v2/entities/{id}/attrs/{name}/value

As an additional side note, note that telling the user "The entity does not have such an attribute: { E1-T1 : [NONE] }" is not very useful for the user in the case of GET /v2/entities/E1/attrs/NONE as the user already knows she has asked for NONE attribute ;)

@Anjali-NEC
Copy link
Contributor Author

I'd suggest to model the case in a .test, roughly this way:

  1. Create entity E with attribute A=1
  2. Do a strict update E A=10 B=20 C=30, get error about entity does not have attribute B and C
  3. Get E, check A=10
  4. Do a strict update E A=100 B=200, get error about entity does not have attribute B
  5. Get E, check A=100

and use that .test to guide your implementation

As per your suggestion I tried to run the above test and in second and forth step I got response "one or more of the attributes in the request already exist: [ A ]" instead of "entity does not have attribute B and C".

Below is the test case I am using:

echo "01. Create entity E with attribute A=1"
echo "======================================"
payload='{
  "id": "E",
  "type": "T",
  "A": {
    "value": 1
  }
}'
orionCurl --url /v2/entities --payload "$payload"
echo
echo


echo "02. Strict update E A=10 B=20 C=30, get error about entity does not have attribute B and C"
echo "=========================================================================================="
payload='{
  "actionType": "appendStrict",
  "entities": [
    {
      "id": "E",
      "type": "T",
      "A": {
        "value": 10
      },
      "B": {
        "value": 20
      },
      "C": {
        "value": 30
      }
    }
  ]
}'
orionCurl --url /v2/op/update --payload "$payload"
echo
echo

echo "03. Get E, check A=10"
echo "====================="
orionCurl --url /v2/entities/E
echo
echo

echo "04. Strict update E A=100 B=200 C=30, get error about entity does not have attribute B"
echo "======================================================================================"
payload='{
  "actionType": "appendStrict",
  "entities": [
    {
      "id": "E",
      "type": "T",
      "A": {
        "value": 100
      },
      "B": {
        "value": 200
      }
    }
  ]
}'
orionCurl --url /v2/op/update --payload "$payload"
echo
echo


echo "05. GET E, check A=100"
echo "======================"
orionCurl --url /v2/entities/E
echo
echo

OUTPUT
01. Create entity E with attribute A=1
======================================
HTTP/1.1 201 Created
Content-Length: 0
Location: /v2/entities/E?type=T
Fiware-Correlator: 16bfee22-cfb0-11ec-b47d-f9ebd88f9903
Date: Mon, 09 May 2022 15:52:54 GMT



02. Strict update E A=10 B=20 C=30, get error about entity does not have attribute B and C
==========================================================================================
HTTP/1.1 422 Unprocessable Entity
Content-Length: 107
Content-Type: application/json
Fiware-Correlator: 16c39996-cfb0-11ec-b47d-f9ebd88f9903
Date: Mon, 09 May 2022 15:52:54 GMT

{
    "description": "one or more of the attributes in the request already exist: [ A ]",
    "error": "Unprocessable"
}


03. Get E, check A=10
=====================
HTTP/1.1 200 OK
Content-Length: 161
Content-Type: application/json
Fiware-Correlator: 16c912ae-cfb0-11ec-b47d-f9ebd88f9903
Date: Mon, 09 May 2022 15:52:54 GMT

{
    "A": {
        "metadata": {},
        "type": "Number",
        "value": 1
    },
    "B": {
        "metadata": {},
        "type": "Number",
        "value": 20
    },
    "C": {
        "metadata": {},
        "type": "Number",
        "value": 30
    },
    "id": "E",
    "type": "T"
}


04. Strict update E A=100 B=200 C=30, get error about entity does not have attribute B
======================================================================================
HTTP/1.1 422 Unprocessable Entity
Content-Length: 110
Content-Type: application/json
Fiware-Correlator: 16cd8546-cfb0-11ec-b47d-f9ebd88f9903
Date: Mon, 09 May 2022 15:52:54 GMT

{
    "description": "one or more of the attributes in the request already exist: [ A, B ]",
    "error": "Unprocessable"
}


05. GET E, check A=100
======================
HTTP/1.1 200 OK
Content-Length: 161
Content-Type: application/json
Fiware-Correlator: 16d1f2b6-cfb0-11ec-b47d-f9ebd88f9903
Date: Mon, 09 May 2022 15:52:54 GMT
{
    "A": {
        "metadata": {},
        "type": "Number",
        "value": 1
    },
    "B": {
        "metadata": {},
        "type": "Number",
        "value": 20
    },
    "C": {
        "metadata": {},
        "type": "Number",
        "value": 30
    },
    "id": "E",
    "type": "T"
}

Please let me know what changes I need to be done in the test case for expected response.

@Anjali-NEC
Copy link
Contributor Author

@fgalan Gentle Reminder!!

@fgalan
Copy link
Member

fgalan commented Sep 13, 2022

Sorry for the delay answering you...

By "strict update" y mean

"actionType": "update",

(Note that "appendStrict" refers to "strict append", which is not the same thant "strict update")

Change that in your .test and let's wee how it goes...

@Anjali-NEC
Copy link
Contributor Author

Sorry for the delay answering you...

By "strict update" y mean

"actionType": "update",

(Note that "appendStrict" refers to "strict append", which is not the same thant "strict update")

Change that in your .test and let's wee how it goes...

After so long waiting for your reply I have started working on another issue. Currently I am little busy on another activity will work on that after in future.

@chandradeep11
Copy link
Contributor

@fgalan
We apology for putting the issue on hold for long period. Anjali-NEC was working on other high priority issue (i.e. #4149). Currently she is on long holiday due to her personal reasons.
Now we have planned to resume working on this ticket in mid of February.

@fgalan
Copy link
Member

fgalan commented Dec 13, 2023

Overpassed by PR #4447

@Anjali-NEC @Chandradeep-NEC I'd recommend you to have a look to that PR for learning purposes, to check how this issue (#3499) can be solved.

@fgalan fgalan closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants