Skip to content

Commit

Permalink
Fix all references to the old "_server_version" attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Mar 6, 2019
1 parent b735456 commit 4e88be5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -3702,7 +3702,7 @@ def conflict_update(self, on_conflict, query):
# Here we need to determine which function to use, which varies
# depending on the MySQL server version. MySQL and MariaDB prior to
# 10.3.3 use "VALUES", while MariaDB 10.3.3+ use "VALUE".
version = self._server_version or (0,)
version = self.server_version or (0,)
if version[0] == 10 and version >= (10, 3, 3):
VALUE_FN = fn.VALUE
else:
Expand Down
9 changes: 1 addition & 8 deletions playhouse/mysql_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ class MySQLConnectorDatabase(MySQLDatabase):
def _connect(self):
if mysql_connector is None:
raise ImproperlyConfigured('MySQL connector not installed!')
conn = mysql_connector.connect(db=self.database, **self.connect_params)
if self._server_version is None:
# MySQL-Connector supports getting the version as a tuple, but this
# method does not return the proper MariaDB version on systems like
# Ubuntu, which express the version as 5.5.5-10.0.37-MariaDB-...
version_raw = conn.get_server_info()
self._server_version = self._extract_server_version(version_raw)
return conn
return mysql_connector.connect(db=self.database, **self.connect_params)

def cursor(self, commit=None):
if self.is_closed():
Expand Down
2 changes: 1 addition & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def new_connection():
IS_MYSQL_ADVANCED_FEATURES = False
if IS_MYSQL:
db.connect()
server_info = db._server_version
server_info = db.server_version
if server_info[0] == 8 or server_info[:2] >= (10, 2):
IS_MYSQL_ADVANCED_FEATURES = True
elif server_info[0] == 0:
Expand Down
6 changes: 3 additions & 3 deletions tests/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ class TestOnConflictMySQL(BaseTestCase):

def setUp(self):
super(TestOnConflictMySQL, self).setUp()
self.database._server_version = None
self.database.server_version = None

def test_replace(self):
query = Person.insert(name='huey').on_conflict('replace')
Expand Down Expand Up @@ -1504,13 +1504,13 @@ def test_update_use_value_mariadb(self):
query = (Person
.insert(name='huey', dob=dob)
.on_conflict(preserve=(Person.dob,)))
self.database._server_version = (10, 3, 3)
self.database.server_version = (10, 3, 3)
self.assertSQL(query, (
'INSERT INTO "person" ("dob", "name") VALUES (?, ?) '
'ON DUPLICATE KEY '
'UPDATE "dob" = VALUE("dob")'), [dob, 'huey'])

self.database._server_version = (10, 3, 2)
self.database.server_version = (10, 3, 2)
self.assertSQL(query, (
'INSERT INTO "person" ("dob", "name") VALUES (?, ?) '
'ON DUPLICATE KEY '
Expand Down

0 comments on commit 4e88be5

Please sign in to comment.