-
Notifications
You must be signed in to change notification settings - Fork 182
Fix tranaction operations when called from the model #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Can one of the admins verify this patch? |
2 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
@raymondfeng @jannyHou @kjdelisle @dhmlau If anyone can add a test reproducing the original issue in #258 I'll investigate further. |
|
@zbarbuto, thanks for your fix. I can try out your fix in a few hours. |
|
Thank you @zbarbuto I will review it asap, and some investigation @dhmlau did yesterday shows the problem is: In postgresql connector's While when the postgresql's if (!(connection instanceof Transaction)) {
tx = new Transaction(connector, connection);
}the code above is get executed since the |
|
@dhmlau Thanks for the steps to reproduce. Can see it happen myself now and am investigating. |
|
@jannyHou You're correct. This is caused when the version of However, I've fixed it to avoid using Not sure the best way to add a test to avoid the regression in the future. Perhaps someone else could advise? |
|
@zbarbuto @jannyHou , the cause of the problem is because there are different definition of cc @raymondfeng |
|
@dhmlau The definition of |
test/postgresql.transaction.test.js
Outdated
|
|
||
| before(function(done) { | ||
| Post.create(p1Content, function(err, p1) { | ||
| Post.create(p1Content, function(err, p2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here it should be p2Content?
|
To avoid the failure of I'm not sure we need to use |
|
@raymondfeng But Moving to |
|
It looks like only |
|
@dhmlau We can probably fix the code at https://github.com/strongloop/loopback-connector/blob/master/lib/transaction.js#L88 as follows: @dhmlau Can you verify? |
|
Verified. Works with and without transaction. |
|
@zbarbuto, do you have a chance to review the suggested changes? Thanks! |
|
Apologize that there has been some environment issue, therefore, the changes were not got reflected when I was doing the testing. I will have to do the verification again. |
|
@dhmlau I'll PR the suggested change to |
|
@dhmlau Update: I just tested with @raymondfeng 's suggested change (with the above changes removed) and tests start failing after the bulk transactions (database deadlocks). |
|
right. there's some problem with the suggested change. @jannyHou proposed something else, let me try it out and let you know. |
|
@zbarbuto , I put @jannyHou 's proposed fix in loopbackio/loopback-connector#107. However, currently there's some issue with the downstream |
|
@zbarbuto, we've implemented a fix in I think the tests that you've added in |
a620839 to
b4dd9b2
Compare
|
@dhmlau Updated tests, removed active transaction tracking and rebased off latest master. |
lib/transaction.js
Outdated
| PostgreSQL.prototype.commit = function(connection, cb) { | ||
| debug('Commit a transaction'); | ||
| var self = this; | ||
| if (connection instanceof Transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested our changes in loopback-connector and it works without any changes in this repo.
Any reason we need to make this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually i think CI failed because of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this in the revert. Have removed now.
lib/transaction.js
Outdated
| PostgreSQL.prototype.rollback = function(connection, cb) { | ||
| debug('Rollback a transaction'); | ||
| var self = this; | ||
| if (connection instanceof Transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
lib/transaction.js
Outdated
| PostgreSQL.prototype.commit = function(connection, cb) { | ||
| debug('Commit a transaction'); | ||
| var self = this; | ||
| if (connection instanceof Transaction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually i think CI failed because of this.
This reverts commit b1a76b3.
0881c5a to
f81e206
Compare
|
Rebased again. |
|
@slnode test please |
| 'use strict'; | ||
| var debug = require('debug')('loopback:connector:postgresql:transaction'); | ||
| var uuid = require('uuid'); | ||
| var Transaction = require('loopback-connector').Transaction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the last one.. i think this is needed.
|
Done |
|
Thanks for going through all this with us! Your PR has landed! |
Description
I was unable to reproduce #258 exactly (when I hear back I will look into this further) but I did find issues when transaction operations where called when Transaction is called from the model.
When called directly on the model, commit and rollback do not go through
transaction.jsinloopback-connectorso what the Postgresql connector is theTransactionrather than theconnection. This PR checks for that case.Related issues
connect to #258
Checklist
guide