Hi, we are using SQL Server Task - SqlServerExecut...
# ask-community
j
Hi, we are using SQL Server Task - SqlServerExecute to execute a truncate table query (also merge query). We are encountered this error. The documentation suggests that the data field can be optional - https://docs.prefect.io/api/latest/tasks/sql_server.html#sqlserverexecute we are able to execute SqlServerExecuteMany and SqlServerFetch. Can someone help?
Copy code
Unexpected error: TypeError('execute() takes no keyword arguments')
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/runner.py", line 48, in inner
    new_state = method(self, state, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/prefect/engine/task_runner.py", line 865, in get_task_run_state
    value = prefect.utilities.executors.run_task_with_timeout(
  File "/usr/local/lib/python3.8/site-packages/prefect/utilities/executors.py", line 299, in run_task_with_timeout
    return task.run(*args, **kwargs)  # type: ignore
  File "/usr/local/lib/python3.8/site-packages/prefect/utilities/tasks.py", line 454, in method
    return run_method(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/prefect/tasks/sql_server/sql_server.py", line 90, in run
    executed = cursor.execute(query=query, vars=data)
TypeError: execute() takes no keyword arguments
k
Hey Jay, would you be able to give a code snippet that reproduces this?
j
sql_server_truncate_template=sql_server.SqlServerExecute(db_name='db',user='user',port=1433,host='<http://somedb.database.windows.net|somedb.database.windows.net>',driver='ODBC Driver 17 for SQL Server')
sql_truncate_statement='TRUNCATE TABLE [dbo].[tableName]'
sql_server_truncate_task=sql_server_truncate_template(query=sql_truncate_statement,password=sql_key_from_secret)
I have checked the source code for SqlServerExecute and issue appears to be in the implementation of the execute which accepts the data as the parameter.
executed = cursor.execute(query=query, vars=data)
k
I get what you mean. I can open an issue for this. I guess the workaround for now would be to copy the task and change
executed = cursor.execute(query=query, vars=data)
to
executed = cursor.execute(query, data)
j
I have tested this and it works. No extra parameter needed in this specific use case.
executed=cursor.execute(sql_truncate_statement)
Thanks!
k
Thanks for testing this for me