Skip to content

Commit

Permalink
Fix postgres_ext and mysql_ext to respect autoconnect settig.
Browse files Browse the repository at this point in the history
Fixes #2019
  • Loading branch information
coleifer committed Sep 19, 2019
1 parent 49b667d commit a8850cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ https://github.com/coleifer/peewee/releases
* Extend the mysql `ReconnectMixin` helper to work with mysql-connector.
* Fix mapping of double-precision float in postgres schema reflection.
Previously it mapped to single-precision, now it correctly uses a double.
* Fix issue where `PostgresqlExtDatabase` and `MySQLConnectorDatabase` did not
respect the `autoconnect` setting.

[View commits](https://github.com/coleifer/peewee/compare/3.10.0...master)

Expand Down
5 changes: 4 additions & 1 deletion playhouse/mysql_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def _connect(self):

def cursor(self, commit=None):
if self.is_closed():
self.connect()
if self.autoconnect:
self.connect()
else:
raise InterfaceError('Error, database connection not opened.')
return self._state.conn.cursor(buffered=True)


Expand Down
5 changes: 4 additions & 1 deletion playhouse/postgres_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ def _connect(self):

def cursor(self, commit=None):
if self.is_closed():
self.connect()
if self.autoconnect:
self.connect()
else:
raise InterfaceError('Error, database connection not opened.')
if commit is __named_cursor__:
return self._state.conn.cursor(name=str(uuid.uuid1()))
return self._state.conn.cursor()
Expand Down

0 comments on commit a8850cf

Please sign in to comment.