Skip to content

Commit

Permalink
3.9.2
Browse files Browse the repository at this point in the history
Adds testcase for handling of connection server_version. Ensures that
the connection is set-up and server version set before calling
initialize connection hook.
  • Loading branch information
coleifer committed Mar 6, 2019
1 parent 4e88be5 commit 1f86371
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ https://github.com/coleifer/peewee/releases

## master

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

## 3.9.1
## 3.9.1 and 3.9.2

Includes a bugfix for an `AttributeError` that occurs when using MySQL with the
`MySQLdb` client.
`MySQLdb` client. The 3.9.2 release includes fixes for a test failure.

[View commits](https://github.com/coleifer/peewee/compare/3.9.0...3.9.1)
[View commits](https://github.com/coleifer/peewee/compare/3.9.0...3.9.2)

## 3.9.0

Expand Down
4 changes: 2 additions & 2 deletions peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
mysql = None


__version__ = '3.9.1'
__version__ = '3.9.2'
__all__ = [
'AsIs',
'AutoField',
Expand Down Expand Up @@ -2775,9 +2775,9 @@ def connect(self, reuse_if_open=False):
self._state.reset()
with __exception_wrapper__:
self._state.set_connection(self._connect())
self._initialize_connection(self._state.conn)
if self.server_version is None:
self._set_server_version(self._state.conn)
self._initialize_connection(self._state.conn)
return True

def _initialize_connection(self, conn):
Expand Down
22 changes: 22 additions & 0 deletions tests/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,28 @@ def assertBatches(n_objs, batch_size, n_commits):
assertBatches(12, 12, 1)
assertBatches(12, 13, 1)

def test_server_version(self):
class FakeDatabase(Database):
server_version = None
def _connect(self):
return 1
def _close(self, conn):
pass
def _set_server_version(self, conn):
self.server_version = (1, 33, 7)

db = FakeDatabase(':memory:')
self.assertTrue(db.server_version is None)
db.connect()
self.assertEqual(db.server_version, (1, 33, 7))
db.close()
self.assertEqual(db.server_version, (1, 33, 7))

db.server_version = (1, 2, 3)
db.connect()
self.assertEqual(db.server_version, (1, 2, 3))
db.close()


class TestThreadSafety(ModelTestCase):
nthreads = 4
Expand Down

0 comments on commit 1f86371

Please sign in to comment.