104104from airflow .models .taskreschedule import TaskReschedule
105105from airflow .models .xcom import LazyXComSelectSequence , XCom
106106from airflow .plugins_manager import integrate_macros_plugins
107- from airflow .sdk .definitions ._internal .templater import SandboxedEnvironment
108- from airflow .sdk .definitions .asset import Asset , AssetAlias , AssetNameRef , AssetUniqueKey , AssetUriRef
109- from airflow .sdk .definitions .param import process_params
110- from airflow .sdk .definitions .taskgroup import MappedTaskGroup
111- from airflow .sdk .execution_time .context import InletEventsAccessors
112107from airflow .sentry import Sentry
113108from airflow .settings import task_instance_mutation_hook
114109from airflow .stats import Stats
115110from airflow .ti_deps .dep_context import DepContext
116111from airflow .ti_deps .dependencies_deps import REQUEUEABLE_DEPS , RUNNING_DEPS
117112from airflow .traces .tracer import Trace
118113from airflow .utils import timezone
119- from airflow .utils .context import (
120- ConnectionAccessor ,
121- Context ,
122- OutletEventAccessors ,
123- VariableAccessor ,
124- context_get_outlet_events ,
125- context_merge ,
126- )
127114from airflow .utils .email import send_email
128115from airflow .utils .helpers import prune_dict , render_template_to_string
129116from airflow .utils .log .logging_mixin import LoggingMixin
160147 from airflow .models .dagrun import DagRun
161148 from airflow .sdk .api .datamodels ._generated import AssetProfile
162149 from airflow .sdk .definitions ._internal .abstractoperator import Operator
150+ from airflow .sdk .definitions .asset import AssetNameRef , AssetUniqueKey , AssetUriRef
163151 from airflow .sdk .definitions .dag import DAG
152+ from airflow .sdk .definitions .taskgroup import MappedTaskGroup
164153 from airflow .sdk .types import RuntimeTaskInstanceProtocol
165154 from airflow .typing_compat import Literal
155+ from airflow .utils .context import Context
166156 from airflow .utils .task_group import TaskGroup
167157
168158
@@ -261,6 +251,8 @@ def _run_raw_task(
261251
262252 try :
263253 if ti .task :
254+ from airflow .sdk .definitions .asset import Asset
255+
264256 inlets = [asset .asprofile () for asset in ti .task .inlets if isinstance (asset , Asset )]
265257 outlets = [asset .asprofile () for asset in ti .task .outlets if isinstance (asset , Asset )]
266258 TaskInstance .validate_inlet_outlet_assets_activeness (inlets , outlets , session = session )
@@ -678,6 +670,8 @@ def _execute_task(task_instance: TaskInstance, context: Context, task_orig: Oper
678670 )
679671
680672 def _execute_callable (context : Context , ** execute_callable_kwargs ):
673+ from airflow .utils .context import context_get_outlet_events
674+
681675 try :
682676 # Print a marker for log grouping of details before task execution
683677 log .info ("::endgroup::" )
@@ -903,6 +897,13 @@ def _get_template_context(
903897 PrevSuccessfulDagRunResponse ,
904898 TIRunContext ,
905899 )
900+ from airflow .sdk .definitions .param import process_params
901+ from airflow .sdk .execution_time .context import InletEventsAccessors
902+ from airflow .utils .context import (
903+ ConnectionAccessor ,
904+ OutletEventAccessors ,
905+ VariableAccessor ,
906+ )
906907
907908 integrate_macros_plugins ()
908909
@@ -1347,6 +1348,9 @@ def _get_email_subject_content(
13471348 html_content_err = jinja_env .from_string (default_html_content_err ).render (** default_context )
13481349
13491350 else :
1351+ from airflow .sdk .definitions ._internal .templater import SandboxedEnvironment
1352+ from airflow .utils .context import context_merge
1353+
13501354 if TYPE_CHECKING :
13511355 assert task_instance .task
13521356
@@ -2736,6 +2740,8 @@ def register_asset_changes_in_db(
27362740 outlet_events : list [dict [str , Any ]],
27372741 session : Session = NEW_SESSION ,
27382742 ) -> None :
2743+ from airflow .sdk .definitions .asset import Asset , AssetAlias , AssetNameRef , AssetUniqueKey , AssetUriRef
2744+
27392745 asset_keys = {
27402746 AssetUniqueKey (o .name , o .uri )
27412747 for o in task_outlets
@@ -3682,6 +3688,8 @@ def duration_expression_update(
36823688 def validate_inlet_outlet_assets_activeness (
36833689 inlets : list [AssetProfile ], outlets : list [AssetProfile ], session : Session
36843690 ) -> None :
3691+ from airflow .sdk .definitions .asset import AssetUniqueKey
3692+
36853693 if not (inlets or outlets ):
36863694 return
36873695
@@ -3699,6 +3707,8 @@ def validate_inlet_outlet_assets_activeness(
36993707 def _get_inactive_asset_unique_keys (
37003708 asset_unique_keys : set [AssetUniqueKey ], session : Session
37013709 ) -> set [AssetUniqueKey ]:
3710+ from airflow .sdk .definitions .asset import AssetUniqueKey
3711+
37023712 active_asset_unique_keys = {
37033713 AssetUniqueKey (name , uri )
37043714 for name , uri in session .execute (
@@ -3724,6 +3734,7 @@ def _find_common_ancestor_mapped_group(node1: Operator, node2: Operator) -> Mapp
37243734def _is_further_mapped_inside (operator : Operator , container : TaskGroup ) -> bool :
37253735 """Whether given operator is *further* mapped inside a task group."""
37263736 from airflow .sdk .definitions .mappedoperator import MappedOperator
3737+ from airflow .sdk .definitions .taskgroup import MappedTaskGroup
37273738
37283739 if isinstance (operator , MappedOperator ):
37293740 return True
0 commit comments