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

ImplicitThingCreation incorrect response when the thing already exists #1704

Open
desislava-marinova opened this issue Jul 24, 2023 · 6 comments
Labels

Comments

@desislava-marinova
Copy link
Contributor

desislava-marinova commented Jul 24, 2023

ImplicitThingCreation mapper is configured as follows:

"implicitEdgeThingCreation": {
      "mappingEngine": "ImplicitThingCreation",
      "options": {
        "thing": {
          "thingId": "{{ header:device_id }}",
          "_copyPolicyFrom": "{{ header:gateway_id }}",
          "attributes": {
            "Info": {
              "gatewayId": "{{ header:gateway_id }}"
            }
          }
        }
      },
      "incomingConditions": {
        "behindGateway": "fn:filter(header:gateway_id, 'exists')"
      }
    }

According to the ImplicitThingCreation mapper configuration

commandHeaders (optional, default: {"If-None-Match": "*"}): The Ditto headers to use for constructing the “create thing” command for creating the twin and to use for creating errors.

The expectation is that the mapper should not fail with error creating policy but should result in

{
    "status": 412,
    "error": "things:precondition.failed",
    ....
}

Currently, the mapper fails with an error with status 400

{
  "correlationId": "ebdd03fd-dc20-487c-af42-91ac5628624a",
  "timestamp": "2023-07-27T11:37:46.994466Z",
  "category": "response",
  "type": "dispatched",
  "level": "failure",
  "message": "Response was not successful. This may be the case for when a thing could not be found or the authorization subject of the consuming source was not allowed to write a thing. - Message headers: [ditto-origin=e850970b-cac5-436a-bbe8-729684ce89e4, if-none-match=*, ditto-inbound-payload-mapper=implicitEdgeThingCreation, ditto-originator=ditto:ditto, response-required=false, correlation-id=ebdd03fd-dc20-487c-af42-91ac5628624a, ditto-auth-context={\"type\":\"pre-authenticated-connection\",\"subjects\":[\"ditto:ditto\"]}, ditto-entity-id=thing:namespace:my-thing, allow-policy-lockout=true, requested-acks=[]] - Message payload: {\"type\":\"things.responses:errorResponse\",\"status\":400,\"thingId\":\"namespace:my-thing\",\"payload\":{\"status\":400,\"error\":\"things:thing.notcreatable\",\"message\":\"The Thing with ID 'namespace:my-thing' could not be created because creation of its implicit Policy ID 'namespace:my-thing' failed.\",\"description\":\"If you want to use an existing Policy, specify it as 'policyId' in the Thing JSON you create.\"}}",
  "address": "_responses",
  "entityType": "thing",
  "entityId": "namespace:my-thing"
}
@thjaeckle
Copy link
Member

Hi @desislava-marinova
I would have expected that using the header If-None-Match: * should have worked.

So I would see that as bug, if it is tried to create the inline or copied policy and therefore fails completely.

@desislava-marinova
Copy link
Contributor Author

According to the ImplicitThingCreation mapper configuration

commandHeaders (optional, default: {"If-None-Match": "*"}): The Ditto headers to use for constructing the “create thing” command for creating the twin and to use for creating errors.

@thjaeckle, does it mean that without adding explicitly commandHeaders in the mapper configuration, the mapper should not fail with error creating policy but should result in

{
    "status": 412,
    "error": "things:precondition.failed",
    ....
}

@thjaeckle
Copy link
Member

Yes, I would also think/assume so ..

@desislava-marinova
Copy link
Contributor Author

Thanks @thjaeckle
Should I create a new bug ticket for that misbehavior, or could this be reused?

@thjaeckle
Copy link
Member

I would reuse this one and rephrase accordingly :)

@desislava-marinova desislava-marinova changed the title Is it possible to use ImplicitThingCreation only if the thing does not exist ImplicitThingCreation incorrect response when the thing already exists Jul 27, 2023
@desislava-marinova
Copy link
Contributor Author

The description and title were updated.

@thjaeckle thjaeckle added the bug label Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants