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

put-metadata does not work as expected since 3.x #1631

Closed
demetz opened this issue May 2, 2023 · 5 comments · Fixed by #1774
Closed

put-metadata does not work as expected since 3.x #1631

demetz opened this issue May 2, 2023 · 5 comments · Fixed by #1774
Labels
Milestone

Comments

@demetz
Copy link

demetz commented May 2, 2023

We recently upgraded from 2.x to the latest version.

I am no longer able to set metadata for a single property:

url = 'https://xxx/api/2/things/[thingid]/features/myfeature/properties/myproperty/temperature'

metadata = [
    {
        "key":"/unit",
        "value": "°C"
    }
]

r = requests.put(url, headers={"Content-Type":"application/json", "put-metadata":json.dumps(metadata)}, auth=(ditto_user, ditto_pass),json=64.5)

Expected behavior: value is written and metadata is available /features/myfeature/properties/myproperty/temperature/unit

Actual behavior: only value is written

@thjaeckle
Copy link
Member

Hi @demetz
Thanks for reporting this issue.

There were some enhancements to metadata in Ditto 3.0, I assume some behavior may have changed.

Could you please try using no trailing slash in the "key", so:

{
        "key":"unit",
        "value": "°C"
    }

I could imagine that this somehow changed if Iook at the docs.

@demetz
Copy link
Author

demetz commented May 2, 2023

unfortunately, same result: ditto returns a 204 and the actual value is written, however no metadata is created.

specifying a nested key (e.g. /test/unit) for _metadata works as expected.

@thjaeckle
Copy link
Member

thjaeckle commented May 3, 2023

Could reproduce via sandbox:

curl --location --request PUT 'https://ditto.eclipseprojects.io/api/2/things/org.eclipse.ditto:lamp01/features/LampFeature/properties/powerConsumption' \
--header 'Authorization: Basic ZGl0dG86ZGl0dG8=' \
--header 'put-metadata: [{"key":"unit","value": "Watts"}]' \
--header 'Content-Type: application/json' \
--data '23.23'

Retrieving the metadata:

curl --location --request GET 'https://ditto.eclipseprojects.io/api/2/things/org.eclipse.ditto:lamp01?fields=thingId%2Cfeatures%2C_metadata' \
--header 'Authorization: Basic ZGl0dG86ZGl0dG8='

Did not apply the metadata as expected ("powerConsumption" is an empty object instead of having the "unit" key):

{
    "thingId": "org.eclipse.ditto:lamp01",
    "features": {
        "LampFeature": {
            "properties": {
                "powerConsumption": 23.23
            }
        }
    },
    "_metadata": {
        "features": {
            "LampFeature": {
                "properties": {
                    "powerConsumption": {}
                }
            }
        }
    }
}

As @demetz mentioned, using a nested key works:

curl --location --request PUT 'https://ditto.eclipseprojects.io/api/2/things/org.eclipse.ditto:lamp01/features/LampFeature/properties/powerConsumption' \
--header 'Authorization: Basic ZGl0dG86ZGl0dG8=' \
--header 'put-metadata: [{"key":"test/unit","value": "Watts"}]' \
--header 'Content-Type: application/json' \
--data '23.23'

Result:

{
    "thingId": "org.eclipse.ditto:lamp01",
    "features": {
        "LampFeature": {
            "properties": {
                "powerConsumption": 23.23
            }
        }
    },
    "_metadata": {
        "features": {
            "LampFeature": {
                "properties": {
                    "powerConsumption": {
                        "test": {
                            "unit": "Watts"
                        }
                    }
                }
            }
        }
    }
}

@thjaeckle thjaeckle added the bug label May 3, 2023
@thjaeckle
Copy link
Member

thjaeckle commented May 3, 2023

Any help on fixing this bug would be appreciated, I currently don't have the resources to work on a fix.

thjaeckle added a commit that referenced this issue Oct 15, 2023
Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
@thjaeckle thjaeckle added this to the 3.4.0 milestone Oct 15, 2023
@thjaeckle
Copy link
Member

@demetz will be fixed in upcoming 3.4.0 release

thjaeckle added a commit that referenced this issue Oct 17, 2023
…ngle-property

#1631 fix putting metadata on a single property did not work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants