GeezerVison is showing github.com — datastore: can not runQuery in a transaction · Issue #1138 · googleapis/google-cloud-node
datastore: can not runQuery in a transaction #1138Descriptionhello is running a query in a transaction supposed to be supported? I get errors when doing so (invalid response), while running a query outside of transactions works fine, and reading+writing inside a transaction also works.
I'm trying to do a query with a filter "email ="
sorry I can't provide you code, I do my datastore operations via a self-rolled orm. Activitystephenplusplus commented on Feb 29, 2016 It should work, as far as I know. What version of gcloud are you running? I'll try to reproduce. jasonswearingen commented on Feb 29, 2016 thanks Stephen, i'm using 0.27, since it's supposed to work, i'll do a repro and post it here in a few min. jasonswearingen commented on Feb 29, 2016 here is my repro code:
console.log("################## running datastore transaction query test");
let key = dataset.key(["test", 123]);
dataset.upsert({
key: key,
data: { email: "[email protected]" }
}, (err, upsertResponse) => {
if (err != null) {
console.log("!!!!!!!!!!!!!!!!!!!!!!!! dataset.upsert err", err.message);
throw err;
}
console.log("################## upsert complete");
dataset.runInTransaction((transaction, done) => {
let query = dataset.createQuery("test");
query.filter("email =", "[email protected]");
transaction.runQuery(query, (err, entities) => {
if (err != null) {
console.log("!!!!!!!!!!!!!!!!!!!!!!!! transaction.runQuery err",err.message);
throw err;
}
console.log("################## transaction.runQuery complete");
for (let i = 0; i < entities.length; i++) {
let current = entities[i];
console.log("################## entity " + i, current.key.path.join(), JSON.stringify(current.data));
}
});
}, (err, transactionResponse) => {
if (err != null) {
console.log("!!!!!!!!!!!!!!!!!!!!!!!! transaction.runInTransaction err", err.message);
throw err;
}
console.log("################## transaction.runInTransaction complete");
});
});
and here is my console output:
################## running datastore transaction query test
################## upsert complete
!!!!!!!!!!!!!!!!!!!!!!!! transaction.runQuery err Bad Request
ApiError: Bad Request
at new util.ApiError (C:\repos\stage3\nlib\node_modules\gcloud\lib\common\util.js:92:10)
at Object.parseHttpRespMessage (C:\repos\stage3\nlib\node_modules\gcloud\lib\common\util.js:134:33)
at Request._callback (C:\repos\stage3\nlib\node_modules\gcloud\lib\datastore\request.js:813:31)
at Request.self.callback (C:\repos\stage3\nlib\node_modules\request\request.js:199:22)
at emitTwo (events.js:87:13)
at Request.emit (events.js:172:7)
at Request.<anonymous> (C:\repos\stage3\nlib\node_modules\request\request.js:1036:10)
at emitOne (events.js:82:20)
at Request.emit (events.js:169:7)
at IncomingMessage.<anonymous> (C:\repos\stage3\nlib\node_modules\request\request.js:963:12)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:474:9)
at process._tickCallback (node.js:388:17)
[ERROR] 07:59:27 ApiError
stephenplusplus commented on Feb 29, 2016 jasonswearingen commented on Feb 29, 2016 ok thanks, i don't know much about ancestors (have deliberately avoided them), so pretty sure none of my data uses them, so it looks like I can't query in transactions in my use-case. It seems ok though (and probably better): I worked around this by running my query first, and then run the transaction. stephenplusplus commented on Feb 29, 2016 Cool! Let me know if there are any other questions or issues with this approach.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|