Hi, I'm trying to connect to SQL Server but am run...
# ask-community
r
Hi, I'm trying to connect to SQL Server but am running into some issues. This is a condensed version of my code ^^. Any ideas why I get this TypeError?
Copy code
Traceback (most recent call last):
  File "C:\Users\***\code\pipeline\src\flows_combined_entries.py", line 76, in <module>
    sqlserver.run(query='select * from julitest.entries where id = 50299',
  File "C:\Users\***\code\pipeline\venv\lib\site-packages\prefect\utilities\tasks.py", line 441, in method
    return run_method(self, *args, **kwargs)
  File "C:\Users\***\code\pipeline\venv\lib\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
In fact I'm actually trying to run a delete query
DELETE FROM entries WHERE id IN (?)
. I found this open issue (https://github.com/PrefectHQ/prefect/issues/4342), but I'm also running into problems with
SQLServerExecuteMany
and
SQLServerFetch
. With the first I get errors that I need to provide a list or tuple of data (which I've tried), with the latter there is no record to fetch so I also get an exception. How would I circumvent this?
s
You might be able to use the SqlServerExecuteMany or SqlServerFetch tasks since they don't appear to have the same improper keyword argument bug as that ticket describes. https://github.com/PrefectHQ/prefect/blob/master/src/prefect/tasks/sql_server/sql_server.py
k
Hey @Rinze, the issue there is that the task is written wrong. You can copy the source and paste it and just remove the keywords and it will work. Also have a PR for that. Will try to get it merged.
r
Great idea @Kevin Kho. Got it to work now, thanks!