Fokko closed pull request #4087: [AIRFLOW-2192] Allow non-latin1 usernames with
MySQL back-end
URL: https://github.com/apache/incubator-airflow/pull/4087
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/airflow/config_templates/default_airflow.cfg
b/airflow/config_templates/default_airflow.cfg
index 9a60bb99a7..b09f62c16d 100644
--- a/airflow/config_templates/default_airflow.cfg
+++ b/airflow/config_templates/default_airflow.cfg
@@ -86,6 +86,9 @@ executor = SequentialExecutor
# their website
sql_alchemy_conn = sqlite:///{AIRFLOW_HOME}/airflow.db
+# The encoding for the databases
+sql_engine_encoding = utf-8
+
# If SqlAlchemy should pool database connections.
sql_alchemy_pool_enabled = True
diff --git a/airflow/settings.py b/airflow/settings.py
index 098164cdc7..8f8420ea22 100644
--- a/airflow/settings.py
+++ b/airflow/settings.py
@@ -155,7 +155,7 @@ def configure_orm(disable_connection_pool=False):
engine_args['poolclass'] = NullPool
log.debug("settings.configure_orm(): Using NullPool")
elif 'sqlite' not in SQL_ALCHEMY_CONN:
- # Engine args not supported by sqlite.
+ # Pool size engine args not supported by sqlite.
# If no config value is defined for the pool size, select a reasonable
value.
# 0 means no limit, which could lead to exceeding the Database
connection limit.
try:
@@ -177,6 +177,16 @@ def configure_orm(disable_connection_pool=False):
engine_args['pool_size'] = pool_size
engine_args['pool_recycle'] = pool_recycle
+ try:
+ # Allow the user to specify an encoding for their DB otherwise default
+ # to utf-8 so jobs & users with non-latin1 characters can still use
+ # us.
+ engine_args['encoding'] = conf.get('core', 'SQL_ENGINE_ENCODING')
+ except conf.AirflowConfigException:
+ engine_args['encoding'] = 'utf-8'
+ # For Python2 we get back a newstr and need a str
+ engine_args['encoding'] = engine_args['encoding'].__str__()
+
engine = create_engine(SQL_ALCHEMY_CONN, **engine_args)
reconnect_timeout = conf.getint('core', 'SQL_ALCHEMY_RECONNECT_TIMEOUT')
setup_event_handlers(engine, reconnect_timeout)
diff --git a/tests/core.py b/tests/core.py
index 679ddbc125..191af11ff3 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -2121,6 +2121,11 @@ def test_password_user_authenticate(self):
self.password_user.password = "secure_password"
self.assertTrue(self.password_user.authenticate("secure_password"))
+ def test_password_unicode_user_authenticate(self):
+ self.password_user.username = u"🐼" # This is a panda
+ self.password_user.password = "secure_password"
+ self.assertTrue(self.password_user.authenticate("secure_password"))
+
def test_password_authenticate_session(self):
from airflow.contrib.auth.backends.password_auth import PasswordUser
self.password_user.password = 'test_password'
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services