Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that makes AirflowSecurityManagerV2 leave transactions in the idle in transaction state #39935

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions airflow/www/security_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ def add_limit_view(self, baseview):
)(baseview.blueprint)

@cached_property
@provide_session
def _auth_manager_is_authorized_map(
self, session: Session = NEW_SESSION
self,
) -> dict[str, Callable[[str, str | None, BaseUser | None], bool]]:
"""
Return the map associating a FAB resource name to the corresponding auth manager is_authorized_ API.
Expand All @@ -179,23 +178,26 @@ def _auth_manager_is_authorized_map(
auth_manager = get_auth_manager()
methods = get_method_from_fab_action_map()

def get_connection_id(resource_pk):
@provide_session
def get_connection_id(resource_pk, session: Session = NEW_SESSION):
if not resource_pk:
return None
connection = session.scalar(select(Connection).where(Connection.id == resource_pk).limit(1))
if not connection:
raise AirflowException("Connection not found")
return connection.conn_id

def get_dag_id_from_dagrun_id(resource_pk):
@provide_session
def get_dag_id_from_dagrun_id(resource_pk, session: Session = NEW_SESSION):
if not resource_pk:
return None
dagrun = session.scalar(select(DagRun).where(DagRun.id == resource_pk).limit(1))
if not dagrun:
raise AirflowException("DagRun not found")
return dagrun.dag_id

def get_dag_id_from_task_instance(resource_pk):
@provide_session
def get_dag_id_from_task_instance(resource_pk, session: Session = NEW_SESSION):
if not resource_pk:
return None
composite_pk = json.loads(resource_pk)
Expand All @@ -213,20 +215,22 @@ def get_dag_id_from_task_instance(resource_pk):
raise AirflowException("Task instance not found")
return dag_id

def get_pool_name(resource_pk):
@provide_session
def get_pool_name(resource_pk, session: Session = NEW_SESSION):
if not resource_pk:
return None
pool = session.scalar(select(Pool).where(Pool.id == resource_pk).limit(1))
if not pool:
raise AirflowException("Pool not found")
return pool.pool

def get_variable_key(resource_pk):
@provide_session
def get_variable_key(resource_pk, session: Session = NEW_SESSION):
if not resource_pk:
return None
variable = session.scalar(select(Variable).where(Variable.id == resource_pk).limit(1))
if not variable:
raise AirflowException("Connection not found")
raise AirflowException("Variable not found")
return variable.key

return {
Expand Down
Loading