-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

I looked at SQLAlchemy source code to see examples about `with`
statement support and found something that look suspicious to me.

class Engine:
    ....

    def begin(self, close_with_result=False)
        conn = self.contextual_connect(
                  close_with_result=close_with_result)
        trans = conn.begin()
        return Engine._trans_ctx(conn, trans, close_with_result)

What happens in case conn.begin() fails?

I was assuming that conn.begin always executed a BEGIN SQL command, but
this is not the case.
However some dialects (like informix and MySQL oursql) *do* execute SQL
commands, and these can fail.


Should I fill a bug report?


I have another question, about coding style.
Current SQLAlchemy code create the connection and transaction objects in
the Engine.begin method, and then return an instance of
Engine._trans_ctx class.

What about, instead, creating the connection and transaction objects
inside the __enter__ method of the Engine._trans_ctx class?

Doing this way, one can prevent incorrect usage of the context manager;
that is doing so:

   ctx = db.begin()

should not create a connection that will never be explicitly closed.



Regards   Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+HFywACgkQscQJ24LbaUTE7QCfbxJTk2vujsqik4UNZ4oIPooR
9NgAnArmvpg9qEeJxsGAlseFVykeuJzH
=N3JD
-----END PGP SIGNATURE-----

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to