Fix crash when deserializing operation objects
This commit is contained in:
1 parent
50e9731920
commit
de65ca0921
1 file changed
+6
-1
@@ -691,6 +691,11 @@ export async function getOperations(
|
|||||||
for (const r of res) {
|
for (const r of res) {
|
||||||
const commandKey = r._id.slice(deviceId.length + 1);
|
const commandKey = r._id.slice(deviceId.length + 1);
|
||||||
delete r._id;
|
delete r._id;
|
||||||
|
// Workaround for a bug in v1.2.1 where operation object is saved without deserialization
|
||||||
|
if (typeof r.provisions !== "string") {
|
||||||
|
operations[commandKey] = r;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
r.timestamp = +r.timestamp;
|
r.timestamp = +r.timestamp;
|
||||||
if (r.args) r.args = JSON.parse(r.args);
|
if (r.args) r.args = JSON.parse(r.args);
|
||||||
r.provisions = JSON.parse(r.provisions);
|
r.provisions = JSON.parse(r.provisions);
|
||||||
@@ -712,7 +717,7 @@ export async function saveOperation(
|
|||||||
o["provisions"] = JSON.stringify(operation.provisions);
|
o["provisions"] = JSON.stringify(operation.provisions);
|
||||||
o["retries"] = JSON.stringify(operation.retries);
|
o["retries"] = JSON.stringify(operation.retries);
|
||||||
o["args"] = JSON.stringify(operation.args);
|
o["args"] = JSON.stringify(operation.args);
|
||||||
await operationsCollection.replaceOne({ _id: id }, operation, {
|
await operationsCollection.replaceOne({ _id: id }, o, {
|
||||||
upsert: true,
|
upsert: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user