You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Clearing a dag run with a dynamically mapped task causes a 409 error in the api server that fails the dag run #48538
The error is a 409 in the API server, then the scheduler, I think responding to that:
The scheduler and API server end up fine but the dag run fails without an error log, the logs stop at filling up dagbag:
[2025-03-30, 00:41:25] INFO - DAG bundles loaded: dags-folder: source="airflow.dag_processing.bundles.manager.DagBundlesManager"
[2025-0[3](http://localhost:28080/dags/simple_dynamic_task_mapping/runs/manual__2025-03-30T00:41:15.805919+00:00_U2AisQsa/tasks/get_nums?try_number=2#3)-30, 00:41:25] INFO - Filling up the DagBag from /files/dags/dtm.py: source="airflow.models.dagbag.DagBag"
This does not happen with a dag that does not contain a dynamic task.
What you think should happen instead?
The dag should clear and rerun successfully.
How to reproduce
Run the dag above. Then clear it from the UI and see the error in the api-server and scheduler.
2025-03-30 05:59:38.325308 [warning ] Server error [airflow.sdk.api.client] detail={'detail': {'reason': 'Unique constraint violation', 'statement': 'INSERT INTO task_map (dag_id, task_id, run_id, map_index, length, keys) VALUES (%(dag_id)s, %(task_id)s, %(run_id)s, %(map_index)s, %(length)s, %(keys)s)', 'orig_error': 'duplicate key value violates unique constraint "task_map_pkey"\nDETAIL: Key (dag_id, task_id, run_id, map_index)=(simple_dynamic_task_mapping_new, get_nums, manual__2025-03-30T05:57:54.788032+00:00_5CocwY5o, -1) already exists.\n'}}
[2025-03-30T05:59:38.340+0000] {trace.py:267} ERROR - Task execute_workload[c3a1a240-ecb4-447a-a7d5-1c90d9c8531e] raised unexpected: ServerResponseError('Server returned error')
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 453, in trace_task
R = retval = fun(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 736, in __protected_call__
return self.run(*args, **kwargs)
File "/opt/airflow/providers/celery/src/airflow/providers/celery/executors/celery_executor_utils.py", line 161, in execute_workload
supervise(
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 1153, in supervise
exit_code = process.wait()
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 730, in wait
self._monitor_subprocess()
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 788, in _monitor_subprocess
alive = self._service_subprocess(max_wait_time=max_wait_time) is None
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 625, in _service_subprocess
need_more = socket_handler(key.fileobj)
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 1010, in cb
gen.send(line)
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 514, in handle_requests
self._handle_request(msg, log)
File "/opt/airflow/task-sdk/src/airflow/sdk/execution_time/supervisor.py", line 916, in _handle_request
self.client.xcoms.set(
File "/opt/airflow/task-sdk/src/airflow/sdk/api/client.py", line 332, in set
self.client.post(f"xcoms/{dag_id}/{run_id}/{task_id}/{key}", params=params, json=value)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1145, in post
return self.request(
File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 336, in wrapped_f
return copy(f, *args, **kw)
File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/usr/local/lib/python3.9/concurrent/futures/_base.py", line 391, in __get_result
raise self._exception
File "/usr/local/lib/python3.9/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
File "/opt/airflow/task-sdk/src/airflow/sdk/api/client.py", line 538, in request
return super().request(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 827, in request
return self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 914, in send
response = self._send_handling_auth(
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 942, in _send_handling_auth
response = self._send_handling_redirects(
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 999, in _send_handling_redirects
raise exc
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 982, in _send_handling_redirects
hook(response)
File "/opt/airflow/task-sdk/src/airflow/sdk/api/client.py", line 107, in raise_on_4xx_5xx
return get_json_error(response) or response.raise_for_status()
File "/opt/airflow/task-sdk/src/airflow/sdk/api/client.py", line 103, in get_json_error
raise err
airflow.sdk.api.client.ServerResponseError: Server returned error
[2025-03-30 05:59:41 +0000] [171] [INFO] Handling signal: winch
[2025-03-30 06:01:39 +0000] [171] [INFO] Handling signal: winch
Activity
vatsrahul1001 commentedon Mar 30, 2025
I see error in celery worker logs
vatsrahul1001 commentedon Mar 30, 2025
It failed due to a unique constraint violation while non-mapped task was being inserted into the task_map table.
vatsrahul1001 commentedon Mar 30, 2025
I tried replicating in AF2 and noticed for same DAG we were not insterting records in task_map table.
vikramkoka commentedon Mar 31, 2025
Daniel Standish,
Assigning it to you, since this looks similar to the other mapped task issue. Please feel free to reassign if not
Zifeng-Ma commentedon Aug 5, 2025
Hi, I am experiencing the same error but not in mapped task. (in regular "@task").
[2025-08-05T09:36:41.244+0000] {_client.py:1026} INFO - HTTP Request: PATCH http://localhost:8080/execution/task-instances/01987997-1396-7340-a
f22-7f69d9c86c28/run "HTTP/1.1 409 Conflict"
2025-08-05 09:36:41 [warning ] Server error
[airflow.sdk.api.client] detail={'detail': {'reason': 'invalid_state', 'message$
: 'TI was not in a state where it could be marked as running', 'previous_state': 'scheduled'}}
Can you help me have a look? Thanks!
BruAPAHE commentedon Oct 28, 2025
bump, have some for task mapper
409