airflow: Getting AirflowInactiveAssetInInletOrOutletException in API server after running a DAG using Asset

Apache Airflow version

3.0.0

If “Other Airflow 2 version” selected, which one?

No response

What happened?

  1. We noticed if we trigger a DAG which uses assets we are getting below error in API server
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/gzip.py", line 29, in __call__
    await responder(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/gzip.py", line 126, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/gzip.py", line 46, in __call__
    await self.app(scope, receive, self.send_with_compression)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 181, in __call__
    raise app_exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 140, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 714, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 734, in app
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 460, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/cadwyn/applications.py", line 255, in __call__
    await self.__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 187, in __call__
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 165, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 178, in __call__
    recv_stream.close()
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 175, in __call__
    response = await self.dispatch_func(request, call_next)
  File "/usr/local/lib/python3.9/site-packages/cadwyn/middleware.py", line 117, in dispatch
    response = await call_next(request)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 153, in call_next
    raise app_exc
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/base.py", line 140, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.9/site-packages/cadwyn/routing.py", line 93, in __call__
    await self.process_request(scope=scope, receive=receive, send=send, routes=routes)
  File "/usr/local/lib/python3.9/site-packages/cadwyn/routing.py", line 131, in process_request
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    raise exc
  File "/usr/local/lib/python3.9/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
  File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
  File "/usr/local/lib/python3.9/site-packages/cadwyn/structure/versions.py", line 474, in decorator
    response = await self._convert_endpoint_response_to_version(
  File "/usr/local/lib/python3.9/site-packages/cadwyn/structure/versions.py", line 520, in _convert_endpoint_response_to_version
    response_or_response_body: Union[FastapiResponse, object] = await run_in_threadpool(
  File "/usr/local/lib/python3.9/site-packages/starlette/concurrency.py", line 37, in run_in_threadpool
    return await anyio.to_thread.run_sync(func)
  File "/usr/local/lib/python3.9/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 2470, in run_sync_in_worker_thread
    return await future
  File "/usr/local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 967, in run
    result = context.run(func, *args)
  File "/usr/local/lib/python3.9/site-packages/cadwyn/schema_generation.py", line 503, in __call__
    return self._original_callable(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py", line 311, in ti_update_state
    TI.register_asset_changes_in_db(
  File "/opt/airflow/airflow-core/src/airflow/utils/session.py", line 99, in wrapper
    return func(*args, **kwargs)
  File "/opt/airflow/airflow-core/src/airflow/models/taskinstance.py", line 2843, in register_asset_changes_in_db
    raise AirflowInactiveAssetInInletOrOutletException(bad_asset_keys)
airflow.exceptions.AirflowInactiveAssetInInletOrOutletException: Task has the following inactive assets in its inlets or outlets: Asset(name='transformed_data', uri='transformed_data')

What you think should happen instead?

No response

How to reproduce

  1. Use below below-mentioned DAGs, which has Asset.
  2. Start breeze instance.
  3. Check that DAGs are visible in UI, also notice that when we open the assets page, the assets are not listed.
  4. Trigger DAG and notice an issue in API server.
from airflow.sdk import dag, Asset
from airflow.decorators import task


@dag(schedule="@daily")  # A
def extracted_data():  # B
    @task(outlets=[Asset("extracted_data")])  # C
    def my_task():
        print("Hello World")

    my_task()

extracted_data()


@dag(schedule=[Asset("extracted_data")])  # D
def transformed_data():
    @task(outlets=[Asset("transformed_data")])  # C
    def my_task():
        print("Hello World")

    my_task()

transformed_data()

@dag(schedule=[Asset("transformed_data")])  # D
def loaded_data():
    @task(outlets=[Asset("loaded_data", uri="test")])  # C
    def my_task():
        print("Hello World")

    my_task()

loaded_data()

Operating System

Linux

Versions of Apache Airflow Providers

No response

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

Fixed merged; @TJaniF can you verify?

This should fix it #49210

Interestingly, the asset in the mapped task isn’t even picked up by the dag processor at all, let alone activated! It looks like this runs deeper than just assets.

I can reproduce this. We’re likely doing something wrong in dynamic tasks that causes the asset to never be picked up. I’m looking into this.

Raising the priority of this

@TJaniF can you retest once on main?

PR merged, do we want to close this, or re-check the scenarios?