[DB-SIG] conn.close() idempotence

Michael Bayer mike_mp at zzzcomputing.com
Wed Oct 19 05:36:04 CEST 2011


On Oct 18, 2011, at 8:53 PM, Daniele Varrazzo wrote:

> 
> The DBAPI says about conn.close():
> 
>    The connection will be unusable from this point
>    forward; an Error (or subclass) exception will be raised
>    if any operation is attempted with the connection.
> 
> now, is conn.close() an "operation" on the connection? Even if it
> doesn't involve server communication? I don't think an idempotent
> close() violates this rule, so I'm really asking about an
> interpretation of the DBAPI, not a change.
> 
> Another user in the ML pointed out that an idempotent close is also
> the behaviour of the Python file objects.
> 
> My opinion is that the DBAPI test suite can be relaxed and
> conn.close() should have no effect on a closed connection. What do you
> think?

I'm +1 for close() on a closed connection being harmless.  rollback() already has this behavior, as the spec specifies "rolls back the start of any pending transaction", thus allowing for no activity if no transaction is present.



More information about the DB-SIG mailing list