Skip to content

Conversation

josenavas
Copy link
Contributor

While I started working transforming the code base to use transactions, I noticed that it was really hard to maintain a nice code. With the improvement in this PR to the Transaction context management, the code highly improves. It allows to enter multiple times in the context and only do something if we are leaving the last context.
Another change is the removal of the parameter commit=False. The execute function will never commit. Since the committing is automatically performed when exiting the context, you never want to explicitly commit, since through the code you don't know if there is something else in the transaction that shouldn't be committed...

What the changes in here allows you to do is:

def test(trans=None):
    trans = trans if trans is not None else Transaction('test')
    with trans:
       trans.add("do something")
       return trans.execute() # This does not commit

trans = Transaction('foo')
with trans:
   trans.add("do_staff")
   val = test(trans) # This call will not commit the changes inside `test`
   res = trans.execute() # This does not commit

val = test() # This call will commit the changes inside `test`

@josenavas josenavas added this to the Alpha 0.2 milestone Jun 25, 2015
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything -> nothing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@squirrelo
Copy link
Contributor

Couple comments

@josenavas josenavas mentioned this pull request Jun 25, 2015
@josenavas
Copy link
Contributor Author

Ready for another round!

@squirrelo
Copy link
Contributor

👍 if tests pass.

antgonza added a commit that referenced this pull request Jun 26, 2015
@antgonza antgonza merged commit cbebc02 into qiita-spots:improve-sql-queues Jun 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants