Skip to content

tests: Handle DDL command in cur.sql() differently #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions test/pycheck/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,12 @@ def __getattr__(self, name):

def sql(self, query, params=None, **kwargs) -> Any:
self.execute(query, params, **kwargs)
try:
return simplify_query_results(self.fetchall())
except psycopg.ProgrammingError as e:
if "the last operation didn't produce a result" == str(e):
# This happens when the query is a DDL statement
return NoResult
raise
if self.pgresult and self.pgresult.status == psycopg.pq.ExecStatus.COMMAND_OK:
# This happens when the query is a DDL statement. Calling fetchall
# would fail with a ProgrammingError in that case.
return NoResult

return simplify_query_results(self.fetchall())

def dsql(self, query, **kwargs):
"""Run a DuckDB query using duckdb.query()"""
Expand Down Expand Up @@ -365,13 +364,12 @@ def sql(self, query, params=None, **kwargs):

async def sql_coroutine(self, query, params=None, **kwargs) -> Any:
await self.execute(query, params, **kwargs)
try:
return simplify_query_results(await self.fetchall())
except psycopg.ProgrammingError as e:
if "the last operation didn't produce a result" == str(e):
# This happens when the query is a DDL statement
return NoResult
raise
if self.pgresult and self.pgresult.status == psycopg.pq.ExecStatus.COMMAND_OK:
# This happens when the query is a DDL statement. Calling fetchall
# would fail with a ProgrammingError in that case.
return NoResult

return simplify_query_results(await self.fetchall())

def dsql(self, query, **kwargs):
"""Run a DuckDB query using duckdb.query()"""
Expand Down