airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Extended ASCII characters cannot be used in Airflow variables

Open ptylenda opened this issue 10 years ago • 8 comments

Dear Airflow Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Version of Airflow (e.g. a release version, running your own fork, running off master -- provide a git log snippet) : 1.7.0
  • Operating System: 3.13.0-83-generic #127-Ubuntu SMP Fri Mar 11 00:25:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Python Version: Python 2.7.6
  • Stack trace: Traceback (most recent call last): File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/base.py", line 68, in inner return self._run_view(f, *args, **kwargs) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/base.py", line 367, in _run_view return fn(self, *args, **kwargs) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/model/base.py", line 1913, in edit_view return_url=return_url) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/base.py", line 307, in render return render_template(template, **kwargs) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/templating.py", line 128, in render_template context, ctx.app) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask/templating.py", line 110, in _render rv = template.render(context) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render return self.environment.handle_exception(exc_info, True) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception reraise(exc_type, exc_value, tb) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/airflow/www/templates/airflow/model_edit.html", line 1, in top-level template code {% extends 'admin/model/edit.html' %} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 6, in top-level template code <input name="_continue_editing" type="submit" class="btn btn-default" value="{{ _gettext('Save and Continue Editing') }}" /> File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/airflow/www/templates/admin/master.html", line 1, in top-level template code {% extends 'admin/base.html' %} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/base.html", line 30, in top-level template code {% block page_body %} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/airflow/www/templates/admin/master.html", line 80, in block "page_body" {% block body %} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/airflow/www/templates/airflow/model_edit.html", line 11, in block "body" {{ super() }} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 36, in block "body" {% block edit_form %} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 37, in block "edit_form" {{ lib.render_form(form, return_url, extra(), form_opts) }} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 202, in template {% call form_tag(action=action) %} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 182, in template {{ caller() }} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 203, in template {{ render_form_fields(form, form_opts=form_opts) }} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 175, in template {{ render_field(form, f, kwargs) }} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 130, in template {{ field(**kwargs)|safe }} File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/wtforms/fields/core.py", line 153, in __call__ return self.meta.render_field(self, kwargs) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/wtforms/meta.py", line 56, in render_field return field.widget(field, **render_kw) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/wtforms/widgets/core.py", line 264, in __call__ escape(text_type(field._value()), quote=False) File "/home/ubuntu/.virtualenvs/airflow/local/lib/python2.7/site-packages/wtforms/fields/core.py", line 533, in _value return text_type(self.data) if self.data is not None else '' UnicodeDecodeError: 'ascii' codec can't decode byte 0xae in position 506: ordinal not in range(128)

Now that you know a little about me, let me tell you about the issue I am having:

Reproduction Steps

  1. Go to airflow variables
  2. Add a new one, containing non-standard character, in this case "®"
  3. Save
  4. Edit the variable again
  5. Exception occurs. Moreover, DAGs using this variable are not loaded either. I am unable to revert changes in the variable easily

ptylenda avatar Apr 01 '16 23:04 ptylenda

+1 was able to reproduce this on mac OSX as well. Some more observations :

  1. The key, value does end up in reqs.variable table but when it tries to retrieve the view it fails.
  2. This might be related to wtforms used in views.py
  3. To get back the variables tab working, delete the key,value from reqs.variable table.

notifytovishal avatar Apr 02 '16 03:04 notifytovishal

Thanks @notifytovishal, yes, after all I figured out that deleting the variable is the easiest solution :) Still this may be a very common use case that someone wants to use not only extended ASCII chars, but just full unicode

ptylenda avatar Apr 02 '16 09:04 ptylenda

In my case, just add ?charset=utf8 option to sql_alchemy_conn in airflow.cfg resolve this issue. (my mysql charset is configured as utf8)

e.g.

sql_alchemy_conn = mysql://airflow@localhost:3306/airflow?charset=utf8

Attsun1031 avatar Apr 02 '16 14:04 Attsun1031

http://docs.sqlalchemy.org/en/rel_0_7/dialects/mysql.html#unicode

So yes update the connection string and you should be fine. Many mysql servers default to latin1 on connections even if your tables are in UTF-8.

bolkedebruin avatar Apr 02 '16 18:04 bolkedebruin

Thanks guys, it has helped indeed. Is there any certain place in the docs where this can be summarized? I could write a short paragraph about this issue, because it doesn't seem very obvious

ptylenda avatar Apr 02 '16 19:04 ptylenda

@ptylenda that would be great! There's a "common pitfalls" page on the wiki that could be a good start (thought it needs a little formatting) -- https://github.com/airbnb/airflow/wiki/Common-Pitfalls.

jlowin avatar Apr 02 '16 20:04 jlowin

Ok, I have written a short bullet point concerning this one, hope it helps someone :)

ptylenda avatar Apr 05 '16 17:04 ptylenda

Thanks!

jlowin avatar Apr 06 '16 17:04 jlowin