internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: apache/airflow

Issue:
ParamsDict represents the class object itself, not keys and values on Task Instance Details
### Apache Airflow version

2.3.3 (latest released)

### What happened

ParamsDict's printable presentation shows the class object itself like `<airflow.models.param.ParamsDict object at 0x7fd0eba9bb80>` on the page of Task Instance Detail because it does not have `__repr__` method in its class. 

<img width="791" alt="image" src="https://user-images.githubusercontent.com/16971553/180902761-88b9dd9f-7102-4e49-b8b8-0282b31dda56.png">

It used to be `dict` object and what keys and values Params include are shown on UI before replacing Params with the advanced Params by #17100. 



### What you think should happen instead

It was originally shown below when it was `dict` object. 

![image](https://user-images.githubusercontent.com/16971553/180904396-7b527877-5bc6-48d2-938f-7d338dfd79a7.png)


I think it can be fixed by adding `__repr__` method to the class like below.

```python
class ParamsDict(dict):
    ...
    def __repr__(self):
        return f"{self.dump()}"
```

### How to reproduce

I guess it all happens on Airflow using 2.2.0+

### Operating System

Linux, but it's not depending on OS

### Versions of Apache Airflow Providers

_No response_

### Deployment

Other

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:

Resolving patch:
diff --git a/airflow/models/param.py b/airflow/models/param.py
--- a/airflow/models/param.py
+++ b/airflow/models/param.py
@@ -147,6 +147,9 @@ def __delitem__(self, v: str) -> None:
     def __iter__(self):
         return iter(self.__dict)
 
+    def __repr__(self):
+        return repr(self.dump())
+
     def __setitem__(self, key: str, value: Any) -> None:
         """
         Override for dictionary's ``setitem`` method. This method make sure that all values are of


Test patch:
diff --git a/tests/models/test_param.py b/tests/models/test_param.py
--- a/tests/models/test_param.py
+++ b/tests/models/test_param.py
@@ -193,6 +193,10 @@ def test_update(self):
         with pytest.raises(ParamValidationError, match=r'Invalid input for param key: 1 is not'):
             pd.update({'key': 1})
 
+    def test_repr(self):
+        pd = ParamsDict({'key': Param('value', type='string')})
+        assert repr(pd) == "{'key': 'value'}"
+
 
 class TestDagParamRuntime:
     VALUE = 42
Repository: apache/airflow

Issue:
resolve web ui views warning re DISTINCT ON
### Body

Got this warning in webserver output when loading home page

```
/Users/dstandish/code/airflow/airflow/www/views.py:710 SADeprecationWarning: DISTINCT ON is currently supported only by the PostgreSQL dialect.  Use of DISTINCT ON for other backends is currently silently ignored, however this usage is deprecated, and will raise CompileError in a future release for all backends that do not support this syntax.
```
looks like it's this line
```
            dagtags = session.query(DagTag.name).distinct(DagTag.name).all()
```

may be able to change to `func.distinct` 



### Committer

- [X] I acknowledge that I am a maintainer/committer of the Apache Airflow project.


Discussion:

Resolving patch:
diff --git a/airflow/www/views.py b/airflow/www/views.py
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -707,7 +707,7 @@ def index(self):
                 else:
                     dag.can_delete = (permissions.ACTION_CAN_DELETE, dag_resource_name) in user_permissions
 
-            dagtags = session.query(DagTag.name).distinct(DagTag.name).all()
+            dagtags = session.query(func.distinct(DagTag.name)).all()
             tags = [
                 {"name": name, "selected": bool(arg_tags_filter and name in arg_tags_filter)}
                 for name, in dagtags


Test patch:
Repository: apache/airflow

Issue:
Choose setting for sqlalchemy SQLALCHEMY_TRACK_MODIFICATIONS
### Body

We need to determine what to do about this warning:

```
/Users/dstandish/.virtualenvs/2.4.0/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:872 FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
```

Should we set to true or false?

@ashb @potiuk @jedcunningham @uranusjr 

### Committer

- [X] I acknowledge that I am a maintainer/committer of the Apache Airflow project.


Discussion:
Looking at the answers here https://stackoverflow.com/questions/33738467/how-do-i-know-if-i-can-disable-sqlalchemy-track-modifications, we should set it to `False`. From what I checked, we do not seem to use "models_committed" or "before_models_committed" anywhere - neither Airflow nor any other dependency uses it (except flask_sqlalchemy that defines it of course). 


Agreed, False.

Resolving patch:
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -656,6 +656,7 @@ def _create_db_from_orm(session):
     def _create_flask_session_tbl():
         flask_app = Flask(__name__)
         flask_app.config['SQLALCHEMY_DATABASE_URI'] = conf.get('database', 'SQL_ALCHEMY_CONN')
+        flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
         db = SQLAlchemy(flask_app)
         AirflowDatabaseSessionInterface(app=flask_app, db=db, table='session', key_prefix='')
         db.create_all()


Test patch:
Repository: apache/airflow

Issue:
Handle TODO: .first() is not None can be changed to .scalar()
### Body

The TODO part of:
https://github.com/apache/airflow/blob/d67ac5932dabbf06ae733fc57b48491a8029b8c2/airflow/models/serialized_dag.py#L156-L158

can now be addressed since we are on sqlalchemy 1.4+ and https://github.com/sqlalchemy/sqlalchemy/issues/5481 is resolved


### Committer

- [X] I acknowledge that I am a maintainer/committer of the Apache Airflow project.


Discussion:
hey @eladkal ,i would like to work on this issue. Please assign it to me.
#self-assign

Resolving patch:
diff --git a/airflow/models/serialized_dag.py b/airflow/models/serialized_dag.py
--- a/airflow/models/serialized_dag.py
+++ b/airflow/models/serialized_dag.py
@@ -149,12 +149,8 @@ def write_dag(
                         (timezone.utcnow() - timedelta(seconds=min_update_interval)) < cls.last_updated,
                     )
                 )
-                .first()
-                is not None
+                .scalar()
             ):
-                # TODO: .first() is not None can be changed to .scalar() once we update to sqlalchemy 1.4+
-                # as the associated sqlalchemy bug for MySQL was fixed
-                # related issue : https://github.com/sqlalchemy/sqlalchemy/issues/5481
                 return False
 
         log.debug("Checking if DAG (%s) changed", dag.dag_id)


Test patch:
Repository: apache/airflow

Issue:
Improve filtering for invalid schemas in Hive hook
### Description

#27647 has introduced filtering for invalid schemas in Hive hook based on the characters `;` and `!`. I'm wondering if a more generic filtering could be introduced, e.g. one that adheres to the regex `[^a-z0-9_]`, since Hive schemas (and table names) can only contain alphanumeric characters and the character `_`.

Note: since the Hive metastore [stores schemas and tables in lowercase](https://stackoverflow.com/questions/57181316/how-to-keep-column-names-in-camel-case-in-hive/57183048#57183048), checking against `[^a-z0-9_]` is probably better than `[^a-zA-Z0-9_]`.

### Use case/motivation

Ensure that Hive schemas used in `apache-airflow-providers-apache-hive` hooks contain no invalid characters.

### Related issues

_No response_

### Are you willing to submit a PR?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:

Resolving patch:
diff --git a/airflow/providers/apache/hive/hooks/hive.py b/airflow/providers/apache/hive/hooks/hive.py
--- a/airflow/providers/apache/hive/hooks/hive.py
+++ b/airflow/providers/apache/hive/hooks/hive.py
@@ -204,8 +204,12 @@ def run_cli(
         """
         conn = self.conn
         schema = schema or conn.schema
-        if "!" in schema or ";" in schema:
-            raise RuntimeError(f"The schema `{schema}` contains invalid characters (!;)")
+
+        invalid_chars_list = re.findall(r"[^a-z0-9_]", schema)
+        if invalid_chars_list:
+            invalid_chars = "".join(char for char in invalid_chars_list)
+            raise RuntimeError(f"The schema `{schema}` contains invalid characters: {invalid_chars}")
+
         if schema:
             hql = f"USE {schema};\n{hql}"
 


Test patch:
diff --git a/tests/providers/apache/hive/hooks/test_hive.py b/tests/providers/apache/hive/hooks/test_hive.py
--- a/tests/providers/apache/hive/hooks/test_hive.py
+++ b/tests/providers/apache/hive/hooks/test_hive.py
@@ -133,10 +133,12 @@ def test_run_cli(self, mock_popen, mock_temp_dir):
         )
 
     def test_hive_cli_hook_invalid_schema(self):
-        with pytest.raises(RuntimeError):
+        with pytest.raises(RuntimeError) as error:
             hook = InvalidHiveCliHook()
             hook.run_cli("SHOW DATABASES")
 
+        assert str(error.value) == "The schema `default;` contains invalid characters: ;"
+
     @mock.patch("subprocess.Popen")
     def test_run_cli_with_hive_conf(self, mock_popen):
         hql = (
Repository: apache/airflow

Issue:
Revert "Display parameter values from serialized dag in trigger dag view. (#27482)

This reverts commit 9409293514cef574179a5320ed3ed50881064423.

@tirkarthi we can't view grid view of a dag if the Param type is boolean

```python
int1 = randint(20, 200)
bool1 = []
bools = bool1.append(True) if int1 % 2 == 0 else bool1.append(False)

@task
def fail_if_invalid(val):
        print(val)
        assert type(val[0]) == bool


@dag(
    start_date=datetime(1970, 1, 1),
    schedule_interval=timedelta(days=365 * 30),
    params={"val": Param(False, type="boolean")},
    doc_md=docs,
    tags=["core", "taskflow-api", "dag-params"],
)
def bool_taskflow_test(bool_val):

    # val is a DagParam object
    # print(val)  # <airflow.models.param.DagParam object at 0x103360b50>

    # the task dereferences it
    fail_if_invalid(bool_val)


the_dag = bool_taskflow_test(bool1)
```


Discussion:
Worse than just crashing the grid view this also crashes the scheduler!

Resolving patch:
diff --git a/airflow/serialization/serialized_objects.py b/airflow/serialization/serialized_objects.py
--- a/airflow/serialization/serialized_objects.py
+++ b/airflow/serialization/serialized_objects.py
@@ -560,14 +560,19 @@ def _deserialize_param(cls, param_dict: dict):
         class_: type[Param] = import_string(class_name)
         attrs = ("default", "description", "schema")
         kwargs = {}
+
+        def is_serialized(val):
+            if isinstance(val, dict):
+                return Encoding.TYPE in val
+            if isinstance(val, list):
+                return all(isinstance(item, dict) and Encoding.TYPE in item for item in val)
+            return False
+
         for attr in attrs:
             if attr not in param_dict:
                 continue
             val = param_dict[attr]
-            is_serialized = (isinstance(val, dict) and Encoding.TYPE in val) or (
-                isinstance(val, list) and all(Encoding.TYPE in param for param in val)
-            )
-            if is_serialized:
+            if is_serialized(val):
                 deserialized_val = cls.deserialize(param_dict[attr])
                 kwargs[attr] = deserialized_val
             else:


Test patch:
diff --git a/tests/serialization/test_dag_serialization.py b/tests/serialization/test_dag_serialization.py
--- a/tests/serialization/test_dag_serialization.py
+++ b/tests/serialization/test_dag_serialization.py
@@ -836,6 +836,7 @@ def __init__(self, path: str):
             Param("my value", description="hello", schema={"type": "string"}),
             Param("my value", description="hello"),
             Param(None, description=None),
+            Param([True], type="array", items={"type": "boolean"}),
         ],
     )
     def test_full_param_roundtrip(self, param):
Repository: apache/airflow

Issue:
CSRF token should be expire with session
### Apache Airflow version

2.5.0

### What happened

In the default configuration, the CSRF token [expires in one hour](https://pythonhosted.org/Flask-WTF/config.html#forms-and-csrf). This setting leads to frequent errors in the UI – for no good reason.


### What you think should happen instead

A short expiration date for the CSRF token is not the right value in my view and I [agree with this answer](https://security.stackexchange.com/a/56520/22108) that the CSRF token should basically never expire, instead pegging itself to the current session.

That is, the CSRF token should last as long as the current session. The easiest way to accomplish this is by generating the CSRF token from the session id.



### How to reproduce

_No response_

### 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

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:
Agree. I read a bit about it and there is no parrticular reason why CSRF should expire. Maybe you would like to take a stab on it @malthe  and achange it ?

Resolving patch:
diff --git a/airflow/config_templates/default_webserver_config.py b/airflow/config_templates/default_webserver_config.py
--- a/airflow/config_templates/default_webserver_config.py
+++ b/airflow/config_templates/default_webserver_config.py
@@ -32,6 +32,7 @@
 
 # Flask-WTF flag for CSRF
 WTF_CSRF_ENABLED = True
+WTF_CSRF_TIME_LIMIT = None
 
 # ----------------------------------------------------
 # AUTHENTICATION CONFIG


Test patch:
Repository: apache/airflow

Issue:
AIP-56 - FAB AM - Permissions view
Move permissions view to FAB Auth manager


Discussion:
I'll do this

Resolving patch:
diff --git a/airflow/www/fab_security/views.py b/airflow/auth/managers/fab/views/permissions.py
similarity index 99%
rename from airflow/www/fab_security/views.py
rename to airflow/auth/managers/fab/views/permissions.py
--- a/airflow/www/fab_security/views.py
+++ b/airflow/auth/managers/fab/views/permissions.py
@@ -1,4 +1,3 @@
-#
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
diff --git a/airflow/www/security.py b/airflow/www/security.py
--- a/airflow/www/security.py
+++ b/airflow/www/security.py
@@ -25,6 +25,11 @@
 from sqlalchemy.orm import Session, joinedload
 
 from airflow.auth.managers.fab.models import Permission, Resource, Role, User
+from airflow.auth.managers.fab.views.permissions import (
+    ActionModelView,
+    PermissionPairModelView,
+    ResourceModelView,
+)
 from airflow.auth.managers.fab.views.roles_list import CustomRoleModelView
 from airflow.auth.managers.fab.views.user import (
     CustomUserDBModelView,
@@ -46,11 +51,6 @@
 from airflow.utils.session import NEW_SESSION, provide_session
 from airflow.www.extensions.init_auth_manager import get_auth_manager
 from airflow.www.fab_security.sqla.manager import SecurityManager
-from airflow.www.fab_security.views import (
-    ActionModelView,
-    PermissionPairModelView,
-    ResourceModelView,
-)
 from airflow.www.utils import CustomSQLAInterface
 
 EXISTING_ROLES = {


Test patch:
Repository: apache/airflow

Issue:
Airflow postgres connection field schema points to database name
### Apache Airflow version

2.7.1

### What happened

Airflow's postgres connection configuration form has a field called  'schema'  which is misguiding as values mentioned here is used to refer to the database name instead of the schema name. It should be correctly named to 'database' or 'dbname'

### What you think should happen instead

_No response_

### How to reproduce

create a connection on the web UI and choose connection type as postgres.
Have a dag connect to an postgres server with multiple databases
provide the database name in the 'schema' field of the connection form- this would work if nothing else is incorrect in the etl
now change the value in the schema field of the connection form to refer to a schema- this will fail unexpectedly as the schema name field actually points to the database name.

### Operating System

Windows and Linux

### Versions of Apache Airflow Providers

2.71

### Deployment

Docker-Compose

### 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

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

> now change the value in the schema field of the connection form to refer to a schema- this will fail unexpectedly as the schema name field actually points to the database name.

https://airflow.apache.org/docs/apache-airflow-providers-postgres/stable/connections/postgres.html#postgresql-connection
@dinu-bilt Are you sure that we need to close this issue? At least we could rename field in the Connection UI.

Yes that'd  be ideal. Thanks 
I've marked as "good first issue" it should be a simple change, just need to implements `get_ui_field_behaviour` on PostgresHook

Some examples in other Hooks

https://github.com/apache/airflow/blob/659d94f0ae89f47a7d4b95d6c19ab7f87bd3a60f/airflow/providers/arangodb/hooks/arangodb.py#L137-L154

https://github.com/apache/airflow/blob/284fa7000dd342967935aff39b1a6f83f9afb174/airflow/providers/amazon/aws/hooks/base_aws.py#L793-L819


Resolving patch:
diff --git a/airflow/providers/postgres/hooks/postgres.py b/airflow/providers/postgres/hooks/postgres.py
--- a/airflow/providers/postgres/hooks/postgres.py
+++ b/airflow/providers/postgres/hooks/postgres.py
@@ -362,3 +362,12 @@ def get_openlineage_database_dialect(self, connection) -> str:
     def get_openlineage_default_schema(self) -> str | None:
         """Returns current schema. This is usually changed with ``SEARCH_PATH`` parameter."""
         return self.get_first("SELECT CURRENT_SCHEMA;")[0]
+
+    @staticmethod
+    def get_ui_field_behaviour() -> dict[str, Any]:
+        return {
+            "hidden_fields": [],
+            "relabeling": {
+                "schema": "Database",
+            },
+        }


Test patch:
Repository: apache/airflow

Issue:
dry_run not optional in api for set task instances state
### Apache Airflow version

2.7.2

### What happened

Sent request without dry_run parameter to dags/{dag_id}/updateTaskInstancesState and got a 500 error.

### What you think should happen instead

I should be able to send a request to update task instances state and get a valid response.

### How to reproduce

You can see this by commenting out line 215 in tests/api_connexion/schemas/test_task_instance_schema.py and running tests. This is a similar error to #34563.

### Operating System

Ubuntu 20.04

### Versions of Apache Airflow Providers

_No response_

### Deployment

Docker-Compose

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)



Discussion:

Resolving patch:
diff --git a/airflow/api_connexion/schemas/task_instance_schema.py b/airflow/api_connexion/schemas/task_instance_schema.py
--- a/airflow/api_connexion/schemas/task_instance_schema.py
+++ b/airflow/api_connexion/schemas/task_instance_schema.py
@@ -155,7 +155,7 @@ def validate_form(self, data, **kwargs):
 class SetTaskInstanceStateFormSchema(Schema):
     """Schema for handling the request of setting state of task instance of a DAG."""
 
-    dry_run = fields.Boolean(dump_default=True)
+    dry_run = fields.Boolean(load_default=True)
     task_id = fields.Str(required=True)
     execution_date = fields.DateTime(validate=validate_istimezone)
     dag_run_id = fields.Str()


Test patch:
diff --git a/tests/api_connexion/schemas/test_task_instance_schema.py b/tests/api_connexion/schemas/test_task_instance_schema.py
--- a/tests/api_connexion/schemas/test_task_instance_schema.py
+++ b/tests/api_connexion/schemas/test_task_instance_schema.py
@@ -237,6 +237,22 @@ def test_success(self):
         }
         assert expected_result == result
 
+    def test_dry_run_is_optional(self):
+        data = self.current_input.copy()
+        data.pop("dry_run")
+        result = set_task_instance_state_form.load(self.current_input)
+        expected_result = {
+            "dry_run": True,
+            "execution_date": dt.datetime(2020, 1, 1, 0, 0, tzinfo=dt.timezone(dt.timedelta(0), "+0000")),
+            "include_downstream": True,
+            "include_future": True,
+            "include_past": True,
+            "include_upstream": True,
+            "new_state": "failed",
+            "task_id": "print_the_context",
+        }
+        assert expected_result == result
+
     @pytest.mark.parametrize(
         "override_data",
         [