<h3 dir="auto">Apache Airflow Provider(s)</h3>
<p dir="auto">common-sql</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apache-airflow-providers-amazon==6.0.0
apache-airflow-providers-apache-hive==4.0.1
apache-airflow-providers-apache-livy==3.1.0
apache-airflow-providers-celery==3.0.0
apache-airflow-providers-cncf-kubernetes==4.4.0
apache-airflow-providers-common-sql==1.3.0
apache-airflow-providers-databricks==3.3.0
apache-airflow-providers-dbt-cloud==2.2.0
apache-airflow-providers-elasticsearch==4.2.1
apache-airflow-providers-ftp==3.1.0
apache-airflow-providers-google==8.4.0
apache-airflow-providers-http==4.0.0
apache-airflow-providers-imap==3.0.0
apache-airflow-providers-microsoft-azure==4.3.0
apache-airflow-providers-postgres==5.2.2
apache-airflow-providers-redis==3.0.0
apache-airflow-providers-sftp==4.1.0
apache-airflow-providers-snowflake==3.3.0
apache-airflow-providers-sqlite==3.2.1
apache-airflow-providers-ssh==3.2.0"><pre class="notranslate"><code class="notranslate">apache-airflow-providers-amazon==6.0.0
apache-airflow-providers-apache-hive==4.0.1
apache-airflow-providers-apache-livy==3.1.0
apache-airflow-providers-celery==3.0.0
apache-airflow-providers-cncf-kubernetes==4.4.0
apache-airflow-providers-common-sql==1.3.0
apache-airflow-providers-databricks==3.3.0
apache-airflow-providers-dbt-cloud==2.2.0
apache-airflow-providers-elasticsearch==4.2.1
apache-airflow-providers-ftp==3.1.0
apache-airflow-providers-google==8.4.0
apache-airflow-providers-http==4.0.0
apache-airflow-providers-imap==3.0.0
apache-airflow-providers-microsoft-azure==4.3.0
apache-airflow-providers-postgres==5.2.2
apache-airflow-providers-redis==3.0.0
apache-airflow-providers-sftp==4.1.0
apache-airflow-providers-snowflake==3.3.0
apache-airflow-providers-sqlite==3.2.1
apache-airflow-providers-ssh==3.2.0
</code></pre></div>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.4.3</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Debian Bullseye</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Astronomer</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">What happened</h3>
<p dir="auto">With the latest version of common-sql provider, the <code class="notranslate">get_records</code> from hook is now a ordinary dictionary, causing this KeyError with SqlSensor:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2022-11-29, 00:39:18 UTC] {taskinstance.py:1851} ERROR - Task failed with exception
Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.9/site-packages/airflow/sensors/base.py&quot;, line 189, in execute
    poke_return = self.poke(context)
  File &quot;/usr/local/lib/python3.9/site-packages/airflow/providers/common/sql/sensors/sql.py&quot;, line 98, in poke
    first_cell = records[0][0]
KeyError: 0"><pre class="notranslate"><code class="notranslate">[2022-11-29, 00:39:18 UTC] {taskinstance.py:1851} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/sensors/base.py", line 189, in execute
    poke_return = self.poke(context)
  File "/usr/local/lib/python3.9/site-packages/airflow/providers/common/sql/sensors/sql.py", line 98, in poke
    first_cell = records[0][0]
KeyError: 0
</code></pre></div>
<p dir="auto">I have only tested with Snowflake, I haven't tested it with other databases. Reverting back to 1.2.0 solves the issue.</p>
<h3 dir="auto">What you think should happen instead</h3>
<p dir="auto">It should return an iterable list as usual with the query.</p>
<h3 dir="auto">How to reproduce</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from datetime import datetime

from airflow import DAG
from airflow.providers.common.sql.sensors.sql import SqlSensor

with DAG(
    dag_id=&quot;sql_provider_snowflake_test&quot;,
    schedule=None,
    start_date=datetime(2022, 1, 1),
    catchup=False,
):
    t1 = SqlSensor(
        task_id=&quot;snowflake_test&quot;,
        conn_id=&quot;snowflake&quot;,
        sql=&quot;select 0&quot;,
        fail_on_empty=False,
        poke_interval=20,
        mode=&quot;poke&quot;,
        timeout=60 * 5,
    )"><pre class="notranslate"><code class="notranslate">from datetime import datetime

from airflow import DAG
from airflow.providers.common.sql.sensors.sql import SqlSensor

with DAG(
    dag_id="sql_provider_snowflake_test",
    schedule=None,
    start_date=datetime(2022, 1, 1),
    catchup=False,
):
    t1 = SqlSensor(
        task_id="snowflake_test",
        conn_id="snowflake",
        sql="select 0",
        fail_on_empty=False,
        poke_interval=20,
        mode="poke",
        timeout=60 * 5,
    )
</code></pre></div>
<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"> 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 Provider(s)</h3>
<p dir="auto">common-sql</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto">apache-airflow-providers-google==8.2.0<br>
apache-airflow-providers-http==4.0.0<br>
apache-airflow-providers-salesforce==5.0.0<br>
apache-airflow-providers-slack==5.1.0<br>
apache-airflow-providers-snowflake==3.2.0</p>
<p dir="auto">Issue:<br>
apache-airflow-providers-common-sql==1.3.0</p>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.4.3</p>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Debian GNU/Linux 11 (bullseye)</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Astronomer</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">What happened</h3>
<p dir="auto">Problem occurred when upgrading from common-sql=1.2.0 to common-sql=1.3.0</p>
<p dir="auto">Getting a <code class="notranslate">KEY_ERROR</code> when running a unique_check and null_check on a column.</p>
<p dir="auto">1.3.0 log:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/15257610/204390144-97ae35b7-1a2c-4ee1-9c12-4f3940047cde.png"><img width="1609" alt="Screen Shot 2022-11-28 at 2 01 20 PM" src="https://user-images.githubusercontent.com/15257610/204390144-97ae35b7-1a2c-4ee1-9c12-4f3940047cde.png" style="max-width: 100%;"></a></p>
<p dir="auto">1.2.0 log:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/15257610/204389994-7e8eae17-a346-41ac-84c4-9de4be71af20.png"><img width="1501" alt="Screen Shot 2022-11-28 at 2 00 15 PM" src="https://user-images.githubusercontent.com/15257610/204389994-7e8eae17-a346-41ac-84c4-9de4be71af20.png" style="max-width: 100%;"></a></p>
<h3 dir="auto">What you think should happen instead</h3>
<p dir="auto">Potential causes:</p>
<ul dir="auto">
<li>seems to be indexing based on the test query column <code class="notranslate">COL_NAME</code> instead of the table column <code class="notranslate">STRIPE_ID</code></li>
<li>the <code class="notranslate">record</code> from the test changed types went from a tuple to a list of dictionaries.</li>
<li>no <code class="notranslate">tolerance</code> is specified for these tests, so <code class="notranslate">.get('tolerance')</code> looks like it will cause an error without a default specified like <code class="notranslate">.get('tolerance', None)</code></li>
</ul>
<p dir="auto">Expected behavior:</p>
<ul dir="auto">
<li>these tests continue to pass with the upgrade</li>
<li><code class="notranslate">tolerance</code> is not a required key.</li>
</ul>
<h3 dir="auto">How to reproduce</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from datetime import datetime
from airflow import DAG

from airflow.providers.snowflake.operators.snowflake import SnowflakeOperator
from airflow.providers.common.sql.operators.sql import SQLColumnCheckOperator

my_conn_id = &quot;snowflake_default&quot;

default_args={&quot;conn_id&quot;: my_conn_id}

with DAG(
    dag_id=&quot;airflow_providers_example&quot;,
    schedule=None,
    start_date=datetime(2022, 11, 27),
    default_args=default_args,
) as dag:

    create_table = SnowflakeOperator(
        task_id=&quot;create_table&quot;,
        sql=&quot;&quot;&quot; CREATE OR REPLACE TABLE testing AS (
                        SELECT
                            1 AS row_num,
                            'not null' AS field

                        UNION ALL

                        SELECT
                            2 AS row_num,
                            'test' AS field

                        UNION ALL

                        SELECT
                            3 AS row_num,
                            'test 2' AS field
                    )&quot;&quot;&quot;,
    )

    column_checks = SQLColumnCheckOperator(
        task_id=&quot;column_checks&quot;,
        table=&quot;testing&quot;,
        column_mapping={
            &quot;field&quot;: {&quot;unique_check&quot;: {&quot;equal_to&quot;: 0}, &quot;null_check&quot;: {&quot;equal_to&quot;: 0}}
        },
    )

    create_table &gt;&gt; column_checks"><pre class="notranslate"><code class="notranslate">from datetime import datetime
from airflow import DAG

from airflow.providers.snowflake.operators.snowflake import SnowflakeOperator
from airflow.providers.common.sql.operators.sql import SQLColumnCheckOperator

my_conn_id = "snowflake_default"

default_args={"conn_id": my_conn_id}

with DAG(
    dag_id="airflow_providers_example",
    schedule=None,
    start_date=datetime(2022, 11, 27),
    default_args=default_args,
) as dag:

    create_table = SnowflakeOperator(
        task_id="create_table",
        sql=""" CREATE OR REPLACE TABLE testing AS (
                        SELECT
                            1 AS row_num,
                            'not null' AS field

                        UNION ALL

                        SELECT
                            2 AS row_num,
                            'test' AS field

                        UNION ALL

                        SELECT
                            3 AS row_num,
                            'test 2' AS field
                    )""",
    )

    column_checks = SQLColumnCheckOperator(
        task_id="column_checks",
        table="testing",
        column_mapping={
            "field": {"unique_check": {"equal_to": 0}, "null_check": {"equal_to": 0}}
        },
    )

    create_table &gt;&gt; column_checks
</code></pre></div>
<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"> 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>