Skip to content

Commit

Permalink
Session is not used in _do_render_template_fields (#37856)
Browse files Browse the repository at this point in the history
It's not used so, we should be able to remove it.  The context here is AIP-44 -- it's important to identify which functions require database access and which don't.  For reference, session has not been used in this function since 5d1270c#diff-f373d874912ccfa03918e853ad15aa91d6bfaa1ee75f1676f78c8a756f332ed0L351.
  • Loading branch information
dstandish committed Mar 4, 2024
1 parent 83316b8 commit 1726b93
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 10 deletions.
4 changes: 0 additions & 4 deletions airflow/models/abstractoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from airflow.utils.context import Context
from airflow.utils.db import exists_query
from airflow.utils.log.secrets_masker import redact
from airflow.utils.session import NEW_SESSION, provide_session
from airflow.utils.setup_teardown import SetupTeardownContext
from airflow.utils.sqlalchemy import with_row_locks
from airflow.utils.state import State, TaskInstanceState
Expand Down Expand Up @@ -659,16 +658,13 @@ def get_template_env(self, dag: DAG | None = None) -> jinja2.Environment:
dag = self.get_dag()
return super().get_template_env(dag=dag)

@provide_session
def _do_render_template_fields(
self,
parent: Any,
template_fields: Iterable[str],
context: Context,
jinja_env: jinja2.Environment,
seen_oids: set[int],
*,
session: Session = NEW_SESSION,
) -> None:
"""Override the base to use custom error logging."""
for attr_name in template_fields:
Expand Down
1 change: 0 additions & 1 deletion airflow/models/mappedoperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,5 +829,4 @@ def render_template_fields(
context=context,
jinja_env=jinja_env,
seen_oids=seen_oids,
session=session,
)
5 changes: 0 additions & 5 deletions airflow/template/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
from airflow.utils.helpers import render_template_as_native, render_template_to_string
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.mixins import ResolveMixin
from airflow.utils.session import NEW_SESSION, provide_session

if TYPE_CHECKING:
import jinja2
from sqlalchemy.orm import Session

from airflow import DAG
from airflow.models.operator import Operator
Expand Down Expand Up @@ -103,16 +101,13 @@ def resolve_template_files(self) -> None:
self.log.exception("Failed to get source %s", item)
self.prepare_template()

@provide_session
def _do_render_template_fields(
self,
parent: Any,
template_fields: Iterable[str],
context: Context,
jinja_env: jinja2.Environment,
seen_oids: set[int],
*,
session: Session = NEW_SESSION,
) -> None:
for attr_name in template_fields:
value = getattr(parent, attr_name)
Expand Down

0 comments on commit 1726b93

Please sign in to comment.