Skip to content

Commit

Permalink
Merge pull request #335 from PyPlanet/bugfix/331
Browse files Browse the repository at this point in the history
[BUGFIX] Fixing issue with the unknown string value, the database enc…
  • Loading branch information
tomvlk committed Jun 2, 2017
2 parents 93c698d + d99dfe3 commit 808a061
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pyplanet/conf/project_template/settings/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
'pyplanet.apps.contrib.mapinfo',
'pyplanet.apps.contrib.mx',
'pyplanet.apps.contrib.transactions',
'pyplanet.apps.contrib.sector_times',

# You can optionally enable one of the following apps. Please look at this page for more information:
# http://pypla.net/#app-docs

# Live Ranking App. Useful when playing in Laps, Rounds and all sort of Trackmania game modes.
# 'pyplanet.apps.contrib.live_rankings',

# Dynamic Points Limit is meant for Shootmania Royal.
# 'pyplanet.apps.contrib.dynamic_points',
]
}
2 changes: 1 addition & 1 deletion pyplanet/conf/project_template/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'host': 'localhost',
'user': 'root',
'password': '',
'charset': 'utf8',
'charset': 'utf8mb4',
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions pyplanet/core/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Database:
def __init__(self, engine_cls, instance, *args, **kwargs):
"""
Initiate database.
:param engine_cls: Engine class
:param instance: Instance of the app.
:param args: *
Expand All @@ -45,6 +45,11 @@ def create_from_settings(cls, instance, conf):
db_name = conf['NAME']
db_options = conf['OPTIONS'] if 'OPTIONS' in conf and conf['OPTIONS'] else dict()

# FIX for #331. Replace utf8 by utf8mb4 in the mysql driver encoding.
if conf['ENGINE'] == 'peewee_async.MySQLDatabase' and 'charset' in db_options and db_options['charset'] == 'utf8':
logging.info('Forcing to use \'utf8mb4\' instead of \'utf8\' for the MySQL charset option! (Fix #331).')
db_options['charset'] = 'utf8mb4'

# We will try to load it so we have the validation inside this class.
engine = getattr(importlib.import_module(engine_path), cls_name)
except ImportError:
Expand All @@ -64,10 +69,10 @@ def __fake_allow_sync(self):
def allow_sync(self, *args, **kwargs):
"""
Wrapper around engine allow_sync to allow failover when no async driver.
:param args:
:param kwargs:
:return:
:param args:
:param kwargs:
:return:
"""
if hasattr(self.engine, 'allow_sync'):
return self.engine.allow_sync()
Expand Down

0 comments on commit 808a061

Please sign in to comment.