Closed peolivei2 closed 4 years ago
hah. that's a bit of an embarrassing situation. we could:
suggestions?
According to the docs, $
is not allowed in twin property names (https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-device-twins).
Maybe we can duplicate the update
function as $update
and keep both, so we don't break people who already use update
and want to use the latest version of the SDK. That way can both support this and don't break current applications.
Commenting adding context to this:
update
function as $update
. It would have to be something that would would definitely be a new feature, so at least a minor version bump.update
as a twin property is not the solution, since that would change the device twin spec.Some code analysis:
The present functionality of adding the update property to the device twin will mean that the code to update will be overwritten if someone creates an update property in the twin, which is within the spec.
from twin.ts
private _clearCachedProperties(): void {
const self = this;
this.properties = {
reported : {
update : function(state: any, done: (err?: null) => void): void {
self._updateReportedProperties(state, done);
}
},
desired : {
}
};
}
I think the best solution that we could do is in the future, particularly with Digital Twins / PnP on the way, will be to not touch this api even though it's broken, and rely on the new API. In the future, we should never implement an API like this, that uses functions on the JSON object itself, since the object is mutable and thus could be updated in any way that follows the twins spec.
A future API change in DT/PnP would look something like this:
client.updateReportedProperties(updateObject, callback)
@peolivei2 First of all thanks for bringing this up. We discussed this issue and I would agree that it is highly unfortunate naming that we have implemented, but now with this being release it would be a breaking change so changing this is a nonstarter. We are going to close this issue and if you have additional concerns please ping me and we can continue to talk about it.
@peolivei2, @YoDaMa, @jebrando, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey
According to SDK samples. to update a reported property, you should call the
twin.properties.reported.update
function. However, if I create a reported property calledupdate
, this overwrites the function and twin updates no longer work. See repro below:Which outputs: