[
https://issues.apache.org/jira/browse/AIRFLOW-1246?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16204779#comment-16204779
]
Zachary Lawson commented on AIRFLOW-1246:
-----------------------------------------
Looking deeper into flask_admin I think this is the reason. flask_admin runs an
escape function in it's get_pk_value in the
flask_admin.contrib.sqla.view.ModelView class
(https://github.com/flask-admin/flask-admin/blob/master/flask_admin/contrib/sqla/view.py#L399-L407).
That escape function is imported from flask_admin.contrib.sqla.tools which
imports it from flask_admin.tools. It escapes the CHAR_ESCAPE with two
CHAR_ESCAPE's values.
Those CHAR_ESCAPE values are set as '.':
https://github.com/flask-admin/flask-admin/blob/master/flask_admin/tools.py#L7
Here's the escape function:
https://github.com/flask-admin/flask-admin/blob/master/flask_admin/tools.py#L104-L107
That's then called in the BaseModelView.index_view method here:
https://github.com/flask-admin/flask-admin/blob/master/flask_admin/model/base.py#L1975
And that is then inherited in the flask_admin.contrib.sqla.view.ModelView
class. That is then the base class for airflow.www.AirflowModelView, which is
the base class for airflow.www.ModelViewOnly, which is the base class for
airflow.www.TaskInstanceModelView.
So there is the root cause as far as I can see it. We could possibly reach out
to the flask_admin developers to understand why they are doing this escaping.
However, given that this seems very intentional, the airflow fix I'm proposing
may be the better solution. Knowing that the variable is set in flask_admin we
could do a variant of what I proposed with the task_id included as well
(including a period in the task_id also causes this bug to surface:
{code}
from flask_admin.tools import CHAR_ESCAPE, CHAR_SEPARATOR
def flask_admin_unescape(value):
return (as_unicode(value)
.replace(CHAR_ESCAPE + CHAR_ESCAPE, CHAR_ESCAPE)
.replace(CHAR_ESCAPE + CHAR_SEPARATOR, CHAR_SEPARATOR))
task_id = flask_admin_unescape(task_id)
dag_id = flask_admin_unescape(dag_id)
{code}
An final drastic alternative to change the separator from a '.' to another
character.
I'll make a PR for the airflow side fix.
> Setting a Subdag task Instance State Throws exception
> ------------------------------------------------------
>
> Key: AIRFLOW-1246
> URL: https://issues.apache.org/jira/browse/AIRFLOW-1246
> Project: Apache Airflow
> Issue Type: Bug
> Components: subdag
> Affects Versions: Airflow 1.8
> Reporter: kraman
>
> When there is a parent dag with a subdag trying to set the task instance
> state of any of the task instances in the subdag to ANY of the
> states"failed,running/success" throws the below exception.
> This is nasty when running a local executor the process are not terminated
> and lie around until manually killed.
> ]
> Traceback (most recent call last):
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1988, in
> wsgi_app
> response = self.full_dispatch_request()
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1641, in
> full_dispatch_request
> rv = self.handle_user_exception(e)
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1544, in
> handle_user_exception
> reraise(exc_type, exc_value, tb)
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1639, in
> full_dispatch_request
> rv = self.dispatch_request()
> File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1625, in
> dispatch_request
> return self.view_functions[rule.endpoint](**req.view_args)
> File "/usr/local/lib/python2.7/site-packages/flask_admin/base.py", line 69,
> in inner
> return self._run_view(f, *args, **kwargs)
> File "/usr/local/lib/python2.7/site-packages/flask_admin/base.py", line
> 368, in _run_view
> return fn(self, *args, **kwargs)
> File "/usr/local/lib/python2.7/site-packages/flask_admin/model/base.py",
> line 2068, in action_view
> return self.handle_action()
> File "/usr/local/lib/python2.7/site-packages/flask_admin/actions.py", line
> 113, in handle_action
> response = handler[0](ids)
> File "/usr/local/lib/python2.7/site-packages/airflow/www/views.py", line
> 2341, in action_set_failed
> self.set_task_instance_state(ids, State.FAILED)
> File "/usr/local/lib/python2.7/site-packages/airflow/utils/db.py", line 53,
> in wrapper
> result = func(*args, **kwargs)
> File "/usr/local/lib/python2.7/site-packages/airflow/www/views.py", line
> 2383, in set_task_instance_state
> raise Exception("Ooops")
> Exception: Ooops
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)