Bug #71663 Connector/Python Connections cannot be used with a 'with' statement

Submitted: 11 Feb 2014 7:15 Modified: 15 May 2020 22:52
Reporter: Stephen Lewis Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S4 (Feature request)
Version:1.1.5 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[11 Feb 2014 7:15] Stephen Lewis
Description:
The Connection class does not implement __enter__/__exit__ methods, so Connections can't be used in a 'with' statement.

How to repeat:
with MySqlConnection(some_args) as db:
  ... do something

--> AttributeError: __exit__

Suggested fix:
Something along the lines of rollback/close in __exit__
[15 May 2020 22:52] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/Python 8.0.21 release, and here's the proposed changelog entry from the documentation team:

Implemented context manager support; which is most commonly implemented
using the with statement.

Thank you for the bug report.

This was implemented via WL #13847

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.