heres the source to session.connection() def connection(self, mapper, **kwargs): """returns a Connection corresponding to the given mapper. used by the execute() method which performs select operations for Mapper and Query. if this Session is transactional, the connection will be in the context of this session's transaction. otherwise, the connection is returned by the contextual_connect method, which some Engines override to return a thread-local connection, and will have close_with_result set to True.
the given **kwargs will be sent to the engine's contextual_connect() method, if no transaction is in progress.""" if self.transaction is not None: return self.transaction.connection(mapper) else: return self.get_bind(mapper).contextual_connect(**kwargs) so session.connection() is going to behave differently if you have opened a SessionTransaction or not, since it wants to be part of the existing context but only if there is one. also, session.create_transaction() doesnt use any connections. the connection is only acquired when the session first tries to get a connection off of the SessionTransaction, at which point SessionTransaction uses contextual_connect() and begins a transaction on it, and then stores that connection within the scope of SessionTransaction. in your test #6, calling sessiontransaction.rollback() does nothing because the sessiontransaction was never used to get a connection. if youre really looking to understand the session, its worth a read of session.py, which is a pretty transparent module and should be pretty straightforward to understand. as far as threadlocal impacting contextual_connection, absolutely. the docs explain this in great detail at http://www.sqlalchemy.org/docs/dbengine.myt#dbengine_implicit . in 0.3 I have greatly de-emphasized the "threadlocal" engine strategy since its really only useful for very specific patterns that most people don't actually need. without "threadlocal", the contextual_connect and connect methods of engine do the exact same thing, except contextual_connect includes the "close_with_result" setting. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---