[
https://issues.apache.org/jira/browse/AIRFLOW-6347?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17009374#comment-17009374
]
ASF GitHub Bot commented on AIRFLOW-6347:
-----------------------------------------
kaxil commented on pull request #7092: [AIRFLOW-6347] BugFix: Can't get task
logs when serialization is enabled
URL: https://github.com/apache/airflow/pull/7092
Quoting from Jira:
**Problem**:
When I set next config options in `airflow.cfg`:
```ini
[core]
store_serialized_dags = True
min_serialized_dag_update_interval = 3
```
View with task logs shows infinity Js spinner, while in webserver log I see
next error:
```
[2019-12-25 14:48:57,640] {{app.py:1891}} ERROR - Exception on
/get_logs_with_metadata [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in
wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in
full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in
handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39,
in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in
full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/decorators.py",
line 121, in wrapper
return f(self, *args, **kwargs)
File
"/usr/local/lib/python3.7/site-packages/flask_appbuilder/security/decorators.py",
line 101, in wraps
return f(self, *args, **kwargs)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/decorators.py",
line 56, in wrapper
return f(*args, **kwargs)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/db.py",
line 74, in wrapper
return func(*args, **kwargs)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/views.py",
line 637, in get_logs_with_metadata
logs, metadata = _get_logs_with_metadata(try_number, metadata)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/views.py",
line 628, in _get_logs_with_metadata
logs, metadatas = handler.read(ti, try_number, metadata=metadata)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py",
line 169, in read
log, metadata = self._read(task_instance, try_number_element, metadata)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py",
line 98, in _read
log_relative_path = self._render_filename(ti, try_number)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py",
line 75, in _render_filename
jinja_context = ti.get_template_context()
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/db.py",
line 74, in wrapper
return func(*args, **kwargs)
File
"/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/models/taskinstance.py",
line 1149, in get_template_context
if 'tables' in task.params:
TypeError: argument of type 'NoneType' is not iterable
```
**Solution:**
This is because we use `self.params = params or {}` and where default value
of `params` is `None` in DAG and Operators and Dag S10n ignore all the None
field.
While de-serializing `params` was being set to None because of the following
line:
```python
keys_to_set_none = dag.get_serialized_fields() - encoded_dag.keys() -
cls._CONSTRUCTOR_PARAMS.keys()
for k in keys_to_set_none:
setattr(dag, k, None)
```
---
Issue link: WILL BE INSERTED BY
[boring-cyborg](https://github.com/kaxil/boring-cyborg)
- [x] Description above provides context of the change
- [x] Commit message/PR title starts with `[AIRFLOW-NNNN]`. AIRFLOW-NNNN =
JIRA ID<sup>*</sup>
- [x] Unit tests coverage for changes (not needed for documentation changes)
- [x] Commits follow "[How to write a good git commit
message](http://chris.beams.io/posts/git-commit/)"
- [x] Relevant documentation is updated including usage instructions.
- [x] I will engage committers as explained in [Contribution Workflow
Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
<sup>*</sup> For document-only changes commit message can start with
`[AIRFLOW-XXXX]`.
---
In case of fundamental code change, Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in
[UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
Read the [Pull Request
Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)
for more information.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Can't get task logs in webUI when DAG serialization is enabled
> --------------------------------------------------------------
>
> Key: AIRFLOW-6347
> URL: https://issues.apache.org/jira/browse/AIRFLOW-6347
> Project: Apache Airflow
> Issue Type: Bug
> Components: DAG, webserver
> Affects Versions: 1.10.7
> Reporter: Anton Cherkasov
> Assignee: Kaxil Naik
> Priority: Major
> Attachments: serialization-disabled.png, serialization_enabled.png
>
>
> When I set next config options in airflow.cfg:
> {noformat}
> [core]
> store_serialized_dags = True
> min_serialized_dag_update_interval = 3{noformat}
>
> View with task logs shows infinity Js spinner, while in webserver log I see
> next error:
> {noformat}
> [2019-12-25 14:48:57,640] {{app.py:1891}} ERROR - Exception on
> /get_logs_with_metadata [GET]
> Traceback (most recent call last):
> File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2446, in
> wsgi_app
> response = self.full_dispatch_request()
> File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1951, in
> full_dispatch_request
> rv = self.handle_user_exception(e)
> File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1820, in
> handle_user_exception
> reraise(exc_type, exc_value, tb)
> File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 39, in
> reraise
> raise value
> File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in
> full_dispatch_request
> rv = self.dispatch_request()
> File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in
> dispatch_request
> return self.view_functions[rule.endpoint](**req.view_args)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/decorators.py",
> line 121, in wrapper
> return f(self, *args, **kwargs)
> File
> "/usr/local/lib/python3.7/site-packages/flask_appbuilder/security/decorators.py",
> line 101, in wraps
> return f(self, *args, **kwargs)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/decorators.py",
> line 56, in wrapper
> return f(*args, **kwargs)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/db.py",
> line 74, in wrapper
> return func(*args, **kwargs)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/views.py",
> line 637, in get_logs_with_metadata
> logs, metadata = _get_logs_with_metadata(try_number, metadata)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/www_rbac/views.py",
> line 628, in _get_logs_with_metadata
> logs, metadatas = handler.read(ti, try_number, metadata=metadata)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py",
> line 169, in read
> log, metadata = self._read(task_instance, try_number_element, metadata)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py",
> line 98, in _read
> log_relative_path = self._render_filename(ti, try_number)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/log/file_task_handler.py",
> line 75, in _render_filename
> jinja_context = ti.get_template_context()
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/utils/db.py",
> line 74, in wrapper
> return func(*args, **kwargs)
> File
> "/usr/local/airflow/.local/lib/python3.7/site-packages/airflow/models/taskinstance.py",
> line 1149, in get_template_context
> if 'tables' in task.params:
> TypeError: argument of type 'NoneType' is not iterable{noformat}
> After some investigation I found that *task.params* field is _empty dict_
> when DAG serialization is disabled and this field became _None object_ after
> enabling serialization.
> Screenshot of _Task Instance Details_ view with *enabled* DAG serialization
> feature: !serialization_enabled.png!
>
> Screenshot of _Task Instance Details_ view with *disabled* DAG serialization
> feature:
> !serialization-disabled.png!
>
> See the _params_ field.
> h2. Steps to reproduce:
> # Install Airflow 1.10.7 or upgrade from previous one
> # Upload some DAG and perform tasks.
> # Enable DAG serialization in airflow.conf
> # Restart airflow scheduler and webserver
> # Go to task's log view
> # See infinity spinner and errors in webserver logs
--
This message was sent by Atlassian Jira
(v8.3.4#803005)