Reputation: 520
I'm using NodeJS 10.15 and Sequelize 3.24.3 (sequelize).
I'm just trying to check if a picture is already uploaded (to the db) checking some values, but it seems it cannot execute the query (no error, no warning, nothing, it just doesn't go on, it seems blocked by something).
I'm using a transaction too (there are few inserts and update before and after this function), but it should work according to the documentation.
This is the function
//Just getting tables from the db, it's working in other parts of the project
const models = require('../../models_newdb');
var filenameAlreadyPresent = function(insertInfo) {
return new Promise(function(resolve, reject) {
return models.ReportingPicture.findOne({
transaction: insertInfo.transaction,
where: {
InspectionGroup_ID: insertInfo.insertInfo.inspectionGroupID,
Building_ID: insertInfo.insertInfo.buildingID,
FileName: insertInfo.returnInfo.fileName
}
})
.then(function (results) {
console.log(results);
})
.catch(error => { return reject(error); });
})
.catch(error => { throw error; });
}
Inside insertInfo
we can find all values we need (including transaction). An example is:
InspectionGroup_ID: 33291
Building_ID: 6731
FileName: 33291_FG22502GC1_1638882304007.jpg
Any suggestion?
UPDATE: this is a console.log of insertInfo.transaction
(the 3 dot notation is to hide some project information for my client, dont want to share those, but they are for the project, nothing related to the transaction)
Transaction {
sequelize:
Sequelize {
options:
{ dialect: 'mssql',
dialectModulePath: null,
host: '192.168.1.13',
protocol: 'tcp',
define: {},
query: {},
sync: {},
timezone: 'Europe/Rome',
logging: false,
omitNull: false,
native: false,
replication: false,
ssl: undefined,
pool: [Object],
quoteIdentifiers: true,
hooks: {},
retry: [Object],
transactionType: 'DEFERRED',
isolationLevel: 'REPEATABLE READ',
databaseVersion: '15.0.2000',
typeValidation: false,
benchmark: false,
server: '192.168.1.13',
dialectOptions: [Object] },
config: { ... },
dialect:
MssqlDialect {
sequelize: [Circular],
connectionManager: [ConnectionManager],
QueryGenerator: [Object] },
models: { ... },
modelManager: ModelManager { models: [Array], sequelize: [Circular] },
connectionManager:
ConnectionManager {
sequelize: [Circular],
config: [Object],
dialect: [MssqlDialect],
versionPromise: null,
dialectName: 'mssql',
onProcessExit: [Function: bound ],
lib: [Object],
pool: [Pool] },
importCache: { ... },
test:
{ '$trackRunningQueries': false,
'$runningQueries': 0,
trackRunningQueries: [Function: trackRunningQueries],
verifyNoRunningQueries: [Function: verifyNoRunningQueries] },
queryInterface:
QueryInterface { sequelize: [Circular], QueryGenerator: [Object] } },
savepoints: [],
options:
{ autocommit: true,
type: 'DEFERRED',
isolationLevel: 'REPEATABLE READ',
readOnly: false },
parent: undefined,
id: 'fb84f7cbbc75cd637099',
name: undefined,
connection:
ResourceLock {
resource:
Connection {
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
config: [Object],
reset: [Function: bound reset],
socketClose: [Function: bound socketClose],
socketEnd: [Function: bound socketEnd],
socketConnect: [Function: bound socketConnect],
socketError: [Function: bound socketError],
requestTimeout: [Function: bound requestTimeout],
connectTimeout: [Function: bound connectTimeout],
debug: [Debug],
tokenStreamParser: [Parser],
inTransaction: true,
transactionDescriptors: [Array],
state: [Object],
connectTimer:
Timeout {
_called: false,
_idleTimeout: -1,
_idlePrev: null,
_idleNext: null,
_idleStart: 3975,
_onTimeout: null,
_timerArgs: undefined,
_repeat: null,
_destroyed: false,
[Symbol(unrefed)]: false,
[Symbol(asyncId)]: 3275,
[Symbol(triggerId)]: 3221 },
lib: [Object],
socket: [Socket],
messageIo: [MessageIO],
closed: false,
messageBuffer:
<Buffer 00 00 1a 00 06 01 00 20 00 01 02 00 21 00 01 03 00 22 00 00 04 00 22 00 01 ff 0f 00 07 d0 00 00 02 00 00>,
routingData: undefined,
loggedIn: true,
isSqlBatch: false,
request: undefined,
requestTimer: undefined,
resetConnectionOnNextRequest: false,
procReturnStatusValue: undefined },
previous:
Promise [Object] {
_bitField: 33554432,
_fulfillmentHandler0: undefined,
_rejectionHandler0: [Connection],
_promise0: undefined,
_receiver0: undefined },
uuid: 'fb84f7cbbc75cd637099' }
}
Logging what sequelize is going, it's saying:
Executing (3ab31913c0c08511f65b): ROLLBACK TRANSACTION;
{ Error: rollback has been called on this transaction(3ab31913c0c08511f65b), you can no longer use it. (The rejected query is attached as the 'sql' property of this error)
at Sequelize.query (E:\Progetti\SINA\sios\node_modules\sequelize\lib\sequelize.js:823:17)
at QueryInterface.select (E:\Progetti\SINA\sios\node_modules\sequelize\lib\query-interface.js:708:25)
at Model.<anonymous> (E:\Progetti\SINA\sios\node_modules\sequelize\lib\model.js:1398:32)
at Model.tryCatcher (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\promise.js:729:18)
at _drainQueueStep (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (E:\Progetti\SINA\sios\node_modules\bluebird\js\release\async.js:15:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
sql:
'SELECT [FileName], [InspectionGroup_ID], [Building_ID] FROM [ReportingPicture] AS [ReportingPicture] WHERE [ReportingPicture].[InspectionGroup_ID] = 33291 AND [ReportingPicture].[Building_ID] = 6731 AND [ReportingPicture].[FileName] = N\'33291_FG22501GG1_1638881644010.jpg\';' }
That's weird because uploading other different data (uploaded via json), it works fine...it always worked fine (the function was completed like 2 months ago and always worked fine until now). How can I know what's causing the rollback?
Upvotes: 1
Views: 2552
Reputation: 22783
If you're sure insertInfo.transaction
stores the correct transaction then just remove the mix of Promise
and then/catch
because findOne
already returns Promise
:
var filenameAlreadyPresent = function(insertInfo) {
return models.ReportingPicture.findOne({
transaction: insertInfo.transaction,
where: {
InspectionGroup_ID: insertInfo.insertInfo.inspectionGroupID,
Building_ID: insertInfo.insertInfo.buildingID,
FileName: insertInfo.returnInfo.fileName
}
})
}
Upvotes: 2