Giter Club home page Giter Club logo

psycopg-nestedtransactions's People

Contributors

asqui avatar nigel-gott avatar nvavrova avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

psycopg-nestedtransactions's Issues

Patching of commit/rollback methods prevents ref-counted garbage collection of connection

A side-effect of:

with Transaction(cxn):
    pass

...is that after this block, cxn.commit and cxn.rollback are instance methods bound to cxn, which have a reference to cxn and therefore prevent it from becoming eligible for deterministic garbage collection when it falls out of scope.

This is because _restore_patches() does not correctly undo what _try_patch() does in all cases. Specifically in the case where cxn methods are already patched with an instance-level bound method, the behaviour is correct, but in the simple case where commit and rollack are only defined as functions on type(cxn), the net effect is that they get turned into bound methods on the instance.

In the case where they are not originally bound methods in the starting state, the correct way to restore this is:

del cxn.commit
del cxn.rollback

This will remove the bound methods from the instance dictionary, and allow the type-level functions to be accessible once again.

Prevent manual transaction manipulations on the connection

To guarantee correctness and predictability when introducing this to existing code, we could actively prevent setting cxn.autocommit or calling of cxn.commit() or cxn.rollback() to actively prevent manual transactions being used in conjunction with the context manager.

We could do this by monkey-patching these with an exception thrower while the connection is within the context manager.

Publish documentation

Probably won't be too much documentation in the way of documentation, but it would be nice to publish it to ReadTheDocs as an exercise.

We could use Daniele's starter pack as a starting point and for inspiration and Sphinx reference: https://github.com/evildmp/daniele-procida-starter-docs

The README content should probably move in to these docs, and be replaced with a link to readthedocs.

Don't rollback existing user transactions

Currently if a user does this:

cxn.autocommit = False
cur.execute('INSERT INTO table VALUES ('A'))
with Transaction(cxn):
    cur.execute('INSERT INTO table VALUES ('B'))
    raise Exception("uh oh")

Both inserts will be rolled back because the transaction begins on the first insert and our context manager doesn't start another one at the beginning.

The obvious fix is just commit when we enter into our managed transaction for the very first time from 'user' code (and not when entering into a nested transaction). However i can see this initial commit not being that expected for the user / a hidden gotcha?

We could just throw if someone starts one of our transactions with autocommit off already, but that feels even more horrible.

Set up code coverage monitoring

Using Coveralls? Or something else?

Again, this is probably a bit overkill, but it's a fun exercise to play around and get this infrastructure up and running, even for such a small repo.

Set up a continuous integration build

Do we want to use Travis, or something else?

We should decide what matrix of versions we want to support. I suppose if we're aiming to have this included in psycopg.extras we'll need to at least cover the same matrix of Python and Postgres versions that psycopg supports?

We may also want a third axis for different psycopg versions while this is a separate library?

Package Structure

So we have two packages right now, nestedtransactions and pyscopg-nestedtransactions. What package structure do we actually want? Using a - in a package name in python is horrible so perhaps instead it should be a nested package like:

pyscopg.nestedtransactions

Also if the end goal is getting the code into pyscopg2 itself then I guess the package should be:

pyscopg2.nestedtransactions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.