Hi !
We are experiencing a strange issue about exact same CloudFunction code does not have the same effect on two different database classes (only the class name differs).
It’s happening on a Mumbai server (https://5o8m7xjcginv.usemoralis.com:2053/server) where we run some cloud functions that use the beforeSave
hook to create a row on a different class.
The code looks something like this:
Moralis.Cloud.beforeSave("MyClass", async (request) => {
const MyClass2 = Moralis.Object.extend("MyClass2");
const query = new Moralis.Query(MyClass2);
query.equalTo(
"request_transaction_hash",
request.object.get("transaction_hash")
);
const retrievedStatusRecord = await query.first({ useMasterKey: true });
if (retrievedStatusRecord !== undefined) {
// Transactions might come at any point, already confirmed, unconfirmed, or first unconfirmed and then confirmed
// We only want to handle the event once, so we are using the transaction hash as a unique identifier
return;
}
// Create status record
const statusRecord = new MyClass2();
statusRecord.set(
"request_transaction_hash",
request.object.get("transaction_hash")
);
statusRecord.set("message", "lorem ipsum");
statusRecord.save(null, { useMasterKey: true });
// Do some HTTP request
Moralis.Cloud.httpRequest({ ... });
});
The odd thing is that for some classes it all works as expected, and for other it doesn’t. The HTTP request fires in both cases but the MyClass2 row never gets created. There are no error logs or anything at the time of request.
The only error I can see on the server is an error message MongoError: cannot infer query fields to set, path 'log_index' is matched twice
that appears like once every 24 hours or so. Not sure what it is about but it does not seem related.
We were not calling .then
on the HTTP request promise but I have tried doing it and suggested on the example and logging the answer and everything is fine on that side…
Is there maybe a limit in how long classes can be named ? Character count I mean.
Let me know if you have any ideas what this could be about !
Thank you very much for you help