You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/02/10 04:13:29 UTC
[GitHub] [airflow] gdevanla opened a new issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
gdevanla opened a new issue #14163:
URL: https://github.com/apache/airflow/issues/14163
<!--
Welcome to Apache Airflow! For a smooth issue process, try to answer the following questions.
Don't worry if they're not all applicable; just try to include what you can :-)
If you need to include code snippets or logs, please put them in fenced code
blocks. If they're super-long, please use the details tag like
<details><summary>super-long log</summary> lots of stuff </details>
Please delete these comment blocks before submitting the issue.
-->
<!--
IMPORTANT!!!
PLEASE CHECK "SIMILAR TO X EXISTING ISSUES" OPTION IF VISIBLE
NEXT TO "SUBMIT NEW ISSUE" BUTTON!!!
PLEASE CHECK IF THIS ISSUE HAS BEEN REPORTED PREVIOUSLY USING SEARCH!!!
Please complete the next sections or the issue will be closed.
These questions are the first thing we need to know to understand the context.
-->
**Apache Airflow version**:
2.0.0
**Kubernetes version (if you are using kubernetes)** (use `kubectl version`):
**Environment**:
- **Cloud provider or hardware configuration**:
- **OS** (e.g. from /etc/os-release): "18.04.1 LTS (Bionic Beaver)"
- **Kernel** (e.g. `uname -a`): 4.15.0-130-generic #134-Ubuntu
- **Install tools**:
- **Others**:
**What happened**:
I observer the following exception, in the scheduler intermittently:
```
[2021-02-10 03:51:26,651] {scheduler_job.py:1298} ERROR - Exception when executing SchedulerJob._run_scheduler_loop
Traceback (most recent call last):
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1280, in _execute
self._run_scheduler_loop()
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1354, in _run_scheduler_loop
self.adopt_or_reset_orphaned_tasks()
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/utils/session.py", line 65, in wrapper
return func(*args, session=session, **kwargs)
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1837, in adopt_or_reset_orphaned_tasks
for attempt in run_with_db_retries(logger=self.log):
File "/home/foo/bar/.env38/lib/python3.8/site-packages/tenacity/__init__.py", line 390, in __iter__
do = self.iter(retry_state=retry_state)
File "/home/foo/bar/.env38/lib/python3.8/site-packages/tenacity/__init__.py", line 356, in iter
return fut.result()
File "/home/imcron/py_src/lib/python3.8/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
File "/home/imcron/py_src/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/jobs/scheduler_job.py", line 1882, in adopt_or_reset_orphaned_tasks
to_reset = self.executor.try_adopt_task_instances(tis_to_reset_or_adopt)
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/executors/celery_executor.py", line 478, in try_adopt_task_instances
states_by_celery_task_id = self.bulk_state_fetcher.get_many(
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/executors/celery_executor.py", line 554, in get_many
result = self._get_many_using_multiprocessing(async_results)
File "/home/foo/bar/.env38/lib/python3.8/site-packages/airflow/executors/celery_executor.py", line 595, in _get_many_using_multiprocessing
num_process = min(len(async_results), self._sync_parallelism)
TypeError: object of type 'map' has no len()
```
**What you expected to happen**:
I think the `len` should not be called on the `async_results`, or `map` should not be used in `try_adopt_task_instances`.
**How to reproduce it**:
Not sure how I can reproduce it. But, here are the offending lines:
https://github.com/apache/airflow/blob/90ab60bba877c65cb93871b97db13a179820d28b/airflow/executors/celery_executor.py#L479
Then, this branch gets hit:
https://github.com/apache/airflow/blob/90ab60bba877c65cb93871b97db13a179820d28b/airflow/executors/celery_executor.py#L554
The, we see the failure, here:
https://github.com/apache/airflow/blob/90ab60bba877c65cb93871b97db13a179820d28b/airflow/executors/celery_executor.py#L595
As minimally and precisely as possible. Keep in mind we do not have access to your cluster or dags.
If you are using kubernetes, please attempt to recreate the issue using minikube or kind.
**Anything else we need to know**:
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] RNHTTR commented on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
RNHTTR commented on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-794914976
I think it _probably_ would be sufficient to just cast the map object to a list like above, but I'm not sure how that would affect the performance of `_get_many_from_kv_backend` or `_get_many_from_db_backend` which are called in lieu of `_get_many_using_multiprocessing` if app.backend is an instance of DatabaseBackend or BaseKeyValueStoreBackend, respectively (see [get_many](https://github.com/apache/airflow/blob/90ab60bba877c65cb93871b97db13a179820d28b/airflow/executors/celery_executor.py#L546-L556)). In these methods, the map is converted to a set via [_tasks_list_to_task_ids](https://github.com/apache/airflow/blob/90ab60bba877c65cb93871b97db13a179820d28b/airflow/executors/celery_executor.py#L529-L530), so it doesn't really make sense to convert the map to a list only for it to get converted to a set immediately after.
So, I think it's best to convert the map to a list or set in the method [_get_many_using_multiprocessing](https://github.com/apache/airflow/blob/90ab60bba877c65cb93871b97db13a179820d28b/airflow/executors/celery_executor.py#L594-L595) before it attempts to get the length of the map, and thus would instead get the length of a list or set.
I think this bug snuck by the [test case](https://github.com/apache/airflow/blob/master/tests/executors/test_celery_executor.py#L353-L377) because the test assumes app.backend is set to `DatabaseBackend`, so `_get_many_using_multiprocessing` is never called in the test case.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] RNHTTR edited a comment on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
RNHTTR edited a comment on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-794733933
I think `BulkStateFetcher`'s `get_many` method expects an iterable of `AsyncResult`s. So, I think the map is necessary.
```python
states_by_celery_task_id = self.bulk_state_fetcher.get_many(
map(operator.itemgetter(0), celery_tasks.values())
)
```
This bit creates a map object that gets the 0th element of each tuple (i.e. AsyncResult) in `celery_tasks.values()` I _think_ all we need to do is cast the map object to a list:
```python
list(map(operator.itemgetter(0), celery_tasks.values()))
```
I'm gonna dig a bit deeper to confirm & hopefully submit a PR tomorrow.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] gdevanla commented on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
gdevanla commented on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-780275469
@ashb In our environment, this happens when I 'clear' a dag containing a bunch of nodes to force a re-run. I am not sure if this can consistently be reproduced elsewhere. I will try to reproduce with a smaller example and get back if I see any success.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] ashb closed issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
ashb closed issue #14163:
URL: https://github.com/apache/airflow/issues/14163
--
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:
users@infra.apache.org
[GitHub] [airflow] RNHTTR edited a comment on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
RNHTTR edited a comment on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-794733933
`BulkStateFetcher`'s `get_many` method expects (i think) an iterable of `AsyncResult`s. So, I think the map is necessary.
```python
states_by_celery_task_id = self.bulk_state_fetcher.get_many(
map(operator.itemgetter(0), celery_tasks.values())
)
```
This bit creates a map object that gets the 0th element of each tuple in `celery_tasks.values()` I _think_ all we need to do is cast the map object to a list:
```python
list(map(operator.itemgetter(0), celery_tasks.values()))
```
I'm gonna dig a bit deeper to confirm & hopefully submit a PR tomorrow.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] gdevanla commented on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
gdevanla commented on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-779495878
Is there a work-around for this? Or should we wait for this issue to be fixed? For us this seems to be a blocker for migrating. I am curious to know how others have solved this issue.
Is this an easy fix I can help with in anyway?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] ashb commented on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
ashb commented on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-779940893
@gdevanla Do you have any easy reproduction steps? It's going to be tricky make sure we have actually fixed it without.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [airflow] RNHTTR commented on issue #14163: TypeError: object of type 'map' has no len(): When celery executor multi-processes to get Task Instances
Posted by GitBox <gi...@apache.org>.
RNHTTR commented on issue #14163:
URL: https://github.com/apache/airflow/issues/14163#issuecomment-794733933
`BulkStateFetcher`'s `get_many` method expects (i think) an iterable of `AsyncResult`s. So, I think the map is necessary.
```python
states_by_celery_task_id = self.bulk_state_fetcher.get_many(
map(operator.itemgetter(0), celery_tasks.values())
)
```
This bit creates a map object that gets the 0th element of each tuple in `celery_tasks.values()` I _think_ all we need to do is cast the map object to a list:
```python
list(map(operator.itemgetter(0), celery_tasks.values()))
```
I'm gonna dig a bit deeper to confirm & hopefully submit a PR tomorrow.
----------------------------------------------------------------
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:
users@infra.apache.org