Issue 1:
Apache Airflow version

2.2.2 (latest released)

What happened

I was trying to call task.get_task_instances() but received an error sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type <class 'sqlalchemy.ext.associationproxy.ColumnAssociationProxyInstance'> instead.

Looking at the code, it's trying to order by TaskInstance.execution_date which is an association proxy. https://sourcegraph.com/github.com/apache/airflow@944dcfb/-/blob/airflow/models/baseoperator.py?L1252:21

If I remove the order_by clause, the function would work.

What you expected to happen

The function to return a list of TaskInstance objects

How to reproduce

Python 3.8.7 (default, Dec 22 2020, 16:05:35)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pendulum
>>> from airflow.operators.dummy import DummyOperator
>>> from airflow import DAG
>>> dag = DAG(
... "test",
... start_date=pendulum.parse("20211201"),
... )
>>> with dag:
... task1 = DummyOperator(task_id="test_task")
...
>>> task = dag.get_task("test_task")
>>> task.get_task_instances(start_date="20211201", end_date="20211201")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/airflow/utils/session.py", line 70, in wrapper
return func(*args, session=session, **kwargs)
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/airflow/models/baseoperator.py", line 1257, in get_task_instances
session.query(TaskInstance)
File "<string>", line 2, in order_by
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/base.py", line 227, in generate
fn(self, *args[1:], **kw)
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 1932, in order_by
criterion = self._adapt_col_list(criterion)
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 336, in _adapt_col_list
return [
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 338, in <listcomp>
expression._literal_as_label_reference(o), True, True
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 4678, in _literal_as_label_reference
return _literal_as_text(element)
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 4721, in _literal_as_text
return _literal_as(element, _no_text_coercion)
File "/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 4711, in _literal_as
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type <class 'sqlalchemy.ext.associationproxy.ColumnAssociationProxyInstance'> instead

Operating System

Debian GNU/Linux

Versions of Apache Airflow Providers

No response

Deployment

Other Docker-based deployment

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

Issue 2:
Apache Airflow version

2.2.3 (latest released)

What happened

This is my first time reporting or posting on this forum. Please let me know if I need to provide any more information. Thanks for looking at this!

I have a Python Operator that uses the BaseOperator get_task_instances method and during the execution of this method, I encounter the following error:

This error is from doing an upgrade from airflow 1.10.15 -> 2.2.3.

I am using SQLAlchemy version 1.2.24 but I also tried with version 1.2.23 and encountered the same error. However, I do not think this is a sqlAlchemy issue.

The issue seems to have been introduced with Airflow 2.2.0 (pr: https://github.com/apache/airflow/pull/17719/files), where the TaskInstance.execution_date changed from being a column to this association_proxy. I do not have deep knowledge of SQLAlchemny so I am not sure why this change was made, but it results in it the error I'm getting.

2.2 .0 +

1.10.15

if you follow the stack trace you will get to this chunk of code that leads to the error because the association_proxy has a 'clause_element' attr, but the attr raises the exception in the error when called.

What you expected to happen

No response

How to reproduce

No response

Operating System

Linux from the official airflow helm chart docker image python version 3.7

Versions of Apache Airflow Providers

apache-airflow-providers-amazon 2.4.0

apache-airflow-providers-celery 2.1.0

apache-airflow-providers-cncf-kubernetes 2.2.0

apache-airflow-providers-databricks 2.2.0

apache-airflow-providers-docker 2.3.0

apache-airflow-providers-elasticsearch 2.1.0

apache-airflow-providers-ftp 2.0.1

apache-airflow-providers-google 6.2.0

apache-airflow-providers-grpc 2.0.1

apache-airflow-providers-hashicorp 2.1.1

apache-airflow-providers-http 2.0.1

apache-airflow-providers-imap 2.0.1

apache-airflow-providers-microsoft-azure 3.4.0

apache-airflow-providers-mysql 2.1.1

apache-airflow-providers-odbc 2.0.1

apache-airflow-providers-postgres 2.4.0

apache-airflow-providers-redis 2.0.1

apache-airflow-providers-sendgrid 2.0.1

apache-airflow-providers-sftp 2.3.0

apache-airflow-providers-slack 4.1.0

apache-airflow-providers-sqlite 2.0.1

apache-airflow-providers-ssh 2.3.0

Deployment

Official Apache Airflow Helm Chart

Deployment details

The only extra dependency I am using is awscli==1.20.65. I have changed very little with the deployment besides a few environments variables and some pod annotations.

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