Issue 1:
Python version: 3.6.12

Airflow version: 2.0.1

Node: sandbox-hdp.hortonworks.com

Traceback (most recent call last):

File "/root/airflow/venv/lib64/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app

response = self.full_dispatch_request()

File "/root/airflow/venv/lib64/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request

rv = self.handle_user_exception(e)

File "/root/airflow/venv/lib64/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception

reraise(exc_type, exc_value, tb)

File "/root/airflow/venv/lib64/python3.6/site-packages/flask/compat.py", line 39, in reraise

raise value

File "/root/airflow/venv/lib64/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request

rv = self.dispatch_request()

File "/root/airflow/venv/lib64/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request

return self.view_functionsrule.endpoint

File "/root/airflow/venv/lib64/python3.6/site-packages/airflow/www/auth.py", line 34, in decorated

return func(*args, **kwargs)

File "/root/airflow/venv/lib64/python3.6/site-packages/airflow/www/views.py", line 532, in index

user_permissions = current_app.appbuilder.sm.get_current_user_permissions()

File "/root/airflow/venv/lib64/python3.6/site-packages/airflow/www/security.py", line 229, in get_current_user_permissions

{(perm_view.permission.name, perm_view.view_menu.name) for perm_view in role.permissions}

File "/root/airflow/venv/lib64/python3.6/site-packages/airflow/www/security.py", line 229, in

{(perm_view.permission.name, perm_view.view_menu.name) for perm_view in role.permissions}

File "/root/airflow/venv/lib64/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 453, in get

return self.impl.get(state, dict)

File "/root/airflow/venv/lib64/python3.6/site-packages/sqlalchemy/orm/attributes.py", line 897, in get

value = self.callable_(state, passive)

File "/root/airflow/venv/lib64/python3.6/site-packages/sqlalchemy/orm/strategies.py", line 831, in _load_for_state

% (orm_util.state_str(state), self.key)

sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <PermissionView at 0x7fef4bf3e4e0> is not bound to a Session; lazy load operation of attribute 'view_menu' cannot proceed (Background on this error at: http://sqlalche.me/e/14/bhk3)

Issue 2:
Apache Airflow version

2.4.0

What happened

From v2.4.0，I run dynamic task mapping example, got many warnings.

from airflow import DAG
from airflow.decorators import task
import pendulum as pl

with DAG(
dag_id='test-dynamic-tasks',
description='测试动态task的注册告警',
schedule=None,
start_date=pl.today().add(days=-1),
) as dag:

@task
def sum_it(values):
print(sum(values))

@task
def add_one(i):
return i + 1

added_values = add_one.expand(i = [1,2])
sum_it(added_values)

Warnings like this.

[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Mapped(_PythonDecoratedOperator): add_one>, sum_it already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Task(_PythonDecoratedOperator): sum_it>, add_one already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Mapped(_PythonDecoratedOperator): add_one>, sum_it already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Task(_PythonDecoratedOperator): sum_it>, add_one already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Mapped(_PythonDecoratedOperator): add_one>, sum_it already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Task(_PythonDecoratedOperator): sum_it>, add_one already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Mapped(_PythonDecoratedOperator): add_one>, sum_it already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Task(_PythonDecoratedOperator): sum_it>, add_one already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Mapped(_PythonDecoratedOperator): add_one>, sum_it already registered for DAG: test-dynamic-tasks
[2022-09-30, 09:11:29 CST] {taskmixin.py:205} WARNING - Dependency <Task(_PythonDecoratedOperator): sum_it>, add_one already registered for DAG: test-dynamic-tasks

What you think should happen instead

No response

How to reproduce

No response

Operating System

CentOS Linux release 7.9.2009 (Core)

Versions of Apache Airflow Providers

airflow-code-editor 7.0.0

apache-airflow 2.4.0

apache-airflow-providers-celery 3.0.0

apache-airflow-providers-common-sql 1.1.0

apache-airflow-providers-ftp 3.1.0

apache-airflow-providers-http 4.0.0

apache-airflow-providers-imap 3.0.0

apache-airflow-providers-microsoft-psrp 2.0.0

apache-airflow-providers-microsoft-winrm 3.0.0

apache-airflow-providers-mysql 3.2.0

apache-airflow-providers-redis 3.0.0

apache-airflow-providers-samba 4.0.0

apache-airflow-providers-sftp 4.0.0

apache-airflow-providers-sqlite 3.2.0

apache-airflow-providers-ssh 3.1.0

Deployment

Other

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

I agree to follow this project's Code of Conduct