airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabriel Llobera (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AIRFLOW-27) MsSqlOperator: ERROR - 'pymssql.Connection' object attribute 'autocommit' is read-only
Date Mon, 02 May 2016 08:50:12 GMT
Gabriel Llobera created AIRFLOW-27:
--------------------------------------

             Summary: MsSqlOperator:  ERROR - 'pymssql.Connection' object attribute 'autocommit'
is read-only
                 Key: AIRFLOW-27
                 URL: https://issues.apache.org/jira/browse/AIRFLOW-27
             Project: Apache Airflow
          Issue Type: Bug
         Environment: Ubuntu 14.04.4 LTS
            Reporter: Gabriel Llobera


I have the following code:
{code}
from airflow import DAG
from airflow.operators import MsSqlOperator
from datetime import datetime, timedelta

args = {
    'owner': 'airflow',
    'depends_on_past': True,
    'start_date': datetime(2016, 4, 6, 1, 0),
    'email': ['example@email.com'],
    'email_on_failure': True,
    'email_on_retry': True,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
    'execution_timeout': timedelta(hours=23),
    'priority_weight': 10
}

dag = DAG('dag_name', default_args=args, schedule_interval='0 1 * * *')

t_generate_metadata_csv = MsSqlOperator(task_id='task_id',
                                        sql='SELECT a FROM b',
                                        mssql_conn_id='mssql_conn',
                                        dag=dag)
{code}

And I'm getting this error:
{code}
ERROR - 'pymssql.Connection' object attribute 'autocommit' is read-only
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/airflow/models.py", line 1064, in run
    result = task_copy.execute(context=context)
  File "/usr/local/lib/python2.7/dist-packages/airflow/operators/mssql_operator.py", line
34, in execute
    hook.run(self.sql, parameters=self.parameters)
  File "/usr/local/lib/python2.7/dist-packages/airflow/hooks/dbapi_hook.py", line 101, in
run
    self.set_autocommit(conn, autocommit)
  File "/usr/local/lib/python2.7/dist-packages/airflow/hooks/dbapi_hook.py", line 115, in
set_autocommit
    conn.autocommit = autocommit
{code}

Looking at the source code I think I might know why it fails (I have added links to the referenced
lines in the source code). In dbapi_hook, [if the connection supports autocommit|https://github.com/airbnb/airflow/blob/master/airflow/hooks/dbapi_hook.py#L123]
then we call set_autocommit, which does [conn.autocommit = autocommit|https://github.com/airbnb/airflow/blob/master/airflow/hooks/dbapi_hook.py#L138].

MsSqlHook has [supports_autocommit set to true|https://github.com/airbnb/airflow/blob/master/airflow/hooks/mssql_hook.py#L13],
but the connection type it uses, which is pymssql has no autocommit attribute. [Instead it
is called _autocommit|https://github.com/pymssql/pymssql/blob/f814fd9dedc7cd87fabbe92dfb1b6d19a5ed31a3/src/pymssql.pyx#L209]
and [autocommit is defined as a function|https://github.com/pymssql/pymssql/blob/f814fd9dedc7cd87fabbe92dfb1b6d19a5ed31a3/src/pymssql.pyx#L255]
to turn autocommit on or off.

So it seems that the error is caused by trying to set the conn.autocommit to a boolean value
when it is not actually a variable but a function. This seems to be supported by this [link|http://www.gossamer-threads.com/lists/python/python/514536]
where someone causes the same error by trying to assign a value to a function.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message