airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Frequent Type error from Flask when navigating UI

Open syvineckruyk opened this issue 10 years ago • 8 comments

We frequently encounter the error below at different points when navigating through the UI. Refreshing usually does the trick ...sometimes screen needs to be refresh many times before the requested screen renders in the worst instances restarting the webserver helps.

Are others seeing this ? We have seen this issue in all versions of Airflow we have used in all environments. We are currently running 1.6.2.3

____/ (  (    )   )  \___
/( (  (  )   _    ))  )   )\
((     (   )(    )  )   (   )  )
((/  ( _(   )   (   _) ) (  () )  )
( (  ( (_)   ((    (   )  .((_ ) .  )_
( (  )    (      (  )    )   ) . ) (   )
(  (   (  (   ) (  _  ( _) ).  ) . ) ) ( )
( (  (   ) (  )   (  ))     ) _)(   )  )  )
( (  ( \ ) (    (_  ( ) ( )  )   ) )  )) ( )
(  (   (  (   (_ ( ) ( _    )  ) (  )  )   )
( (  ( (  (  )     (_  )  ) )  _)   ) _( ( )
((  (   )(    (     _    )   _) _(_ (  (_ )
(_((__(_(__(( ( ( |  ) ) ) )_))__))_)___)
((__)        \\||lll|l||///          \_))
  (   /(/ (  )  ) )\   )
(    ( ( ( | | ) ) )\   )
 (   /(| / ( )) ) ) )) )
(     ( ((((_(|)_)))))     )
(      ||\(|(|)|/||     )
(        |(||(||)||||        )
(     //|/l|||)|\\ \     )
(/ / //  /|//||||\\  \ \  \ _)
-------------------------------------------------------------------------------
Node: [REMOVED]
-------------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask_Admin-1.4.0-py2.7.egg/flask_admin/base.py", line 68, in inner
return self._run_view(f, *args, **kwargs)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask_Admin-1.4.0-py2.7.egg/flask_admin/base.py", line 367, in _run_view
return fn(self, *args, **kwargs)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/Flask_Login-0.2.11-py2.7.egg/flask_login.py", line 755, in decorated_view
return func(*args, **kwargs)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/www/utils.py", line 198, in view_func
return f(*args, **kwargs)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/www/utils.py", line 103, in wrapper
return f(*args, **kwargs)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/www/views.py", line 1204, in graph
include_downstream=False)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/models.py", line 2345, in sub_dag
dag = copy.deepcopy(self)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 174, in deepcopy
y = copier(memo)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/models.py", line 2331, in __deepcopy__
setattr(result, k, copy.deepcopy(v, memo))
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 174, in deepcopy
y = copier(memo)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/models.py", line 1607, in __deepcopy__
setattr(result, k, copy.deepcopy(v, memo))
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 174, in deepcopy
y = copier(memo)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/site-packages/airflow-1.6.2-py2.7.egg/airflow/models.py", line 1607, in __deepcopy__
setattr(result, k, copy.deepcopy(v, memo))
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/home/airflow/.pyenv/versions/2.7.10/lib/python2.7/copy.py", line 329, in _reconstruct
y = callable(*args)
File "/home/airflow/.pyenv/versions/airflow/lib/python2.7/copy_reg.py", line 93, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(thread.lock) is not safe, use thread.lock.__new__()

syvineckruyk avatar Feb 27 '16 16:02 syvineckruyk

You must have some funky object attached to your DAG that isn't deepcoypable. Looks at your callbacks, params, default_args and other ways to reference external objects.

In Flask's debug mode it's easy-ish to track down which object is at fault.

mistercrunch avatar Feb 27 '16 17:02 mistercrunch

The deepcopy is used to get subsections of DAGs without altering the original DagBag. We could eventually refactor the code so that copies would be made by loading up a fresh targeted DagBag but since we use the python import system we'd have to play some tricks to it to force a re-import.

mistercrunch avatar Feb 27 '16 17:02 mistercrunch

Cool .. thanks for the debug mode tip ... running in debug now hoping to track down the issue.

syvineckruyk avatar Feb 27 '16 18:02 syvineckruyk

@mistercrunch if an object in my dag was the culprit ... why would refreshing (f5) work ?

it usually happens when i'm trying to clear dag states in the ui... before and/or after the list of task instances that are going to be cleared appears.

Have not gotten it bug out yet since I've been running the webserver in debug. Will keep trying

syvineckruyk avatar Feb 27 '16 20:02 syvineckruyk

I see the same issue using CeleryExector when trying to clear DAG state. My TypeError is: TypeError: object.__new__(generator) is not safe, use generator.__new__() Will try to use debug mode to see which object it doesn't like. We've implemented custom Operators that take other custom objects as their params. Once I find the offending object, what do you suggest @mistercrunch? Implement __copy__/__deepcopy__ for each object?

toryhaavik avatar Mar 03 '16 16:03 toryhaavik

Oddly enough I cannot get it to reproduce when in debug mode ... Though without debug it happens 10(s) of times per day.

@toryhaavik if you manage to trigger it in debug mode and get any extra info it would be greatly appreciated.

syvineckruyk avatar Mar 03 '16 18:03 syvineckruyk

@syvineckruyk I can reliably reproduce mine, and the debug window gives me a different, more obvious error: TypeError: can't pickle generator objects

The object in question is my custom Operator that has a generator attached to it because it reads from HDFS. Still not totally clear on what's being serialized and why, but I think the call we both see to object.__new__() might lead you to a clue. I'd bet that thread.lock is not serializable, and it's attached to your DAG.

But like I said before, I'm not really sure how to handle this, because I need the custom Operator to continue to use its generator.

toryhaavik avatar Mar 03 '16 21:03 toryhaavik

I think the key is to override __deepcopy__ and skip / reattach the offending objects. There's an example of that here for 2 attributes that caused problems: https://github.com/airbnb/airflow/blob/master/airflow/models.py#L2438

You may want to do something similar for your operator.

mistercrunch avatar Mar 04 '16 05:03 mistercrunch