<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.2.2 (latest released)</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">I was trying to call <code class="notranslate">task.get_task_instances()</code> but received an error <code class="notranslate">sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type &lt;class 'sqlalchemy.ext.associationproxy.ColumnAssociationProxyInstance'&gt; instead</code>.</p>
<p dir="auto">Looking at the code, it's trying to order by <code class="notranslate">TaskInstance.execution_date</code> which is an association proxy. <a href="https://sourcegraph.com/github.com/apache/airflow@944dcfb/-/blob/airflow/models/baseoperator.py?L1252:21" rel="nofollow">https://sourcegraph.com/github.com/apache/airflow@944dcfb/-/blob/airflow/models/baseoperator.py?L1252:21</a><br>
If I remove the order_by clause, the function would work.</p>
<h3 dir="auto">What you expected to happen</h3>
<p dir="auto">The function to return a list of TaskInstance objects</p>
<h3 dir="auto">How to reproduce</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Python 3.8.7 (default, Dec 22 2020, 16:05:35)
[GCC 8.3.0] on linux
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import pendulum
&gt;&gt;&gt; from airflow.operators.dummy import DummyOperator
&gt;&gt;&gt; from airflow import DAG
&gt;&gt;&gt; dag = DAG(
...     &quot;test&quot;,
...     start_date=pendulum.parse(&quot;20211201&quot;),
... )
&gt;&gt;&gt; with dag:
...     task1 = DummyOperator(task_id=&quot;test_task&quot;)
...
&gt;&gt;&gt; task = dag.get_task(&quot;test_task&quot;)
&gt;&gt;&gt; task.get_task_instances(start_date=&quot;20211201&quot;, end_date=&quot;20211201&quot;)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/airflow/utils/session.py&quot;, line 70, in wrapper
    return func(*args, session=session, **kwargs)
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/airflow/models/baseoperator.py&quot;, line 1257, in get_task_instances
    session.query(TaskInstance)
  File &quot;&lt;string&gt;&quot;, line 2, in order_by
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/base.py&quot;, line 227, in generate
    fn(self, *args[1:], **kw)
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/query.py&quot;, line 1932, in order_by
    criterion = self._adapt_col_list(criterion)
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/query.py&quot;, line 336, in _adapt_col_list
    return [
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/orm/query.py&quot;, line 338, in &lt;listcomp&gt;
    expression._literal_as_label_reference(o), True, True
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/sql/elements.py&quot;, line 4678, in _literal_as_label_reference
    return _literal_as_text(element)
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/sql/elements.py&quot;, line 4721, in _literal_as_text
    return _literal_as(element, _no_text_coercion)
  File &quot;/home/atl/venv_airflow_2.2.2/lib/python3.8/site-packages/sqlalchemy/sql/elements.py&quot;, line 4711, in _literal_as
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: SQL expression object expected, got object of type &lt;class 'sqlalchemy.ext.associationproxy.ColumnAssociationProxyInstance'&gt; instead"><pre class="notranslate"><code class="notranslate">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.
&gt;&gt;&gt; import pendulum
&gt;&gt;&gt; from airflow.operators.dummy import DummyOperator
&gt;&gt;&gt; from airflow import DAG
&gt;&gt;&gt; dag = DAG(
...     "test",
...     start_date=pendulum.parse("20211201"),
... )
&gt;&gt;&gt; with dag:
...     task1 = DummyOperator(task_id="test_task")
...
&gt;&gt;&gt; task = dag.get_task("test_task")
&gt;&gt;&gt; task.get_task_instances(start_date="20211201", end_date="20211201")
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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 "&lt;string&gt;", 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 &lt;listcomp&gt;
    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 &lt;class 'sqlalchemy.ext.associationproxy.ColumnAssociationProxyInstance'&gt; instead
</code></pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Debian GNU/Linux</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Other Docker-based deployment</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Anything else</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.2.3 (latest released)</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">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!</p>
<p dir="auto">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:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/18559784/154581673-718bc199-8390-49cf-a3fe-8972b6f39f81.png"><img width="1069" alt="Screen Shot 2022-02-17 at 2 28 48 PM" src="https://user-images.githubusercontent.com/18559784/154581673-718bc199-8390-49cf-a3fe-8972b6f39f81.png" style="max-width: 100%;"></a></p>
<p dir="auto">This error is from doing an upgrade from airflow 1.10.15 -&gt; 2.2.3.</p>
<p dir="auto">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.</p>
<p dir="auto">The issue seems to have been introduced with Airflow 2.2.0 (pr: <a href="https://github.com/apache/airflow/pull/17719/files">https://github.com/apache/airflow/pull/17719/files</a>), 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.</p>
<p dir="auto">2.2 .0 +<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/18559784/154583252-4729b44d-40e2-4a89-9018-95b09ef4da76.png"><img width="536" alt="Screen Shot 2022-02-17 at 2 41 00 PM" src="https://user-images.githubusercontent.com/18559784/154583252-4729b44d-40e2-4a89-9018-95b09ef4da76.png" style="max-width: 100%;"></a></p>
<p dir="auto">1.10.15<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/18559784/154585325-4546309c-66b6-4e69-aba2-9b6979762a1b.png"><img width="428" alt="Screen Shot 2022-02-17 at 2 56 15 PM" src="https://user-images.githubusercontent.com/18559784/154585325-4546309c-66b6-4e69-aba2-9b6979762a1b.png" style="max-width: 100%;"></a></p>
<p dir="auto">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 '<strong>clause_element</strong>' attr, but the attr raises the exception in the error when called.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/18559784/154583639-a7957209-b19e-4134-a5c2-88d53176709c.png"><img width="465" alt="Screen Shot 2022-02-17 at 2 43 51 PM" src="https://user-images.githubusercontent.com/18559784/154583639-a7957209-b19e-4134-a5c2-88d53176709c.png" style="max-width: 100%;"></a></p>
<h3 dir="auto">What you expected to happen</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Linux from the official airflow helm chart docker image python version 3.7</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto">apache-airflow-providers-amazon          2.4.0<br>
apache-airflow-providers-celery          2.1.0<br>
apache-airflow-providers-cncf-kubernetes 2.2.0<br>
apache-airflow-providers-databricks      2.2.0<br>
apache-airflow-providers-docker          2.3.0<br>
apache-airflow-providers-elasticsearch   2.1.0<br>
apache-airflow-providers-ftp             2.0.1<br>
apache-airflow-providers-google          6.2.0<br>
apache-airflow-providers-grpc            2.0.1<br>
apache-airflow-providers-hashicorp       2.1.1<br>
apache-airflow-providers-http            2.0.1<br>
apache-airflow-providers-imap            2.0.1<br>
apache-airflow-providers-microsoft-azure 3.4.0<br>
apache-airflow-providers-mysql           2.1.1<br>
apache-airflow-providers-odbc            2.0.1<br>
apache-airflow-providers-postgres        2.4.0<br>
apache-airflow-providers-redis           2.0.1<br>
apache-airflow-providers-sendgrid        2.0.1<br>
apache-airflow-providers-sftp            2.3.0<br>
apache-airflow-providers-slack           4.1.0<br>
apache-airflow-providers-sqlite          2.0.1<br>
apache-airflow-providers-ssh             2.3.0</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Official Apache Airflow Helm Chart</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto">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.</p>
<h3 dir="auto">Anything else</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>