fix: handle CREATE MACRO in server mode to avoid ProgrammingError - #344
fix: handle CREATE MACRO in server mode to avoid ProgrammingError#344mdz wants to merge 3 commits into
Conversation
CREATE MACRO is DuckDB-only DDL that sqlglot parses as an opaque Command, so it matched none of the result_sql branches and left _last_sql as raw DDL. Server mode then called DESCRIBE on that raw DDL, which DuckDB rejected. Give CREATE MACRO a SQL_SUCCESS result_sql like other DDL statements. Fixes tekumara#343 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tekumara
left a comment
There was a problem hiding this comment.
Thanks for this! Just added a suggestion for a test more consistent with the existing tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
||
|
|
||
| def test_description_create_macro(dcur: snowflake.connector.cursor.DictCursor): | ||
| dcur.execute("create or replace macro inc(x) as (x + 1)") |
There was a problem hiding this comment.
it just occurred to me that snowflake doesn't support macros, and you can't run this on a real snowflake instance... so i'm hesitant to support it ... what is the use case for creating macros?
There was a problem hiding this comment.
I've used it to implement support for Snowflake functions that fakesnow doesn't support. But if you prefer, I can submit patches to add first-class support for those instead. Would that be better?
There was a problem hiding this comment.
also, FYI, CREATE MACRO already works [it defines the macro], but emits a spurious error return. if you want to make it fail cleanly, that will require a code change
There was a problem hiding this comment.
I submitted separate issues and PRs for the problems I was working around with CREATE MACRO, along with a PR to reject CREATE MACRO cleanly. We can close this one?
|
Closing in favor of #350 |
Summary
CREATE MACROis DuckDB-only DDL that sqlglot parses as an opaqueCommand, so it matched none of theresult_sqlbranches inFakeSnowflakeCursor._executeand left_last_sqlas the raw DDL string.DESCRIBE <_last_sql>unconditionally, soDESCRIBE CREATE OR REPLACE MACRO …hit DuckDB's parser and raised aProgrammingError, even though the macro was created successfully._executethat detectsCREATE … MACRO(via regex on the opaqueCommand.expression) and assignsSQL_SUCCESSas theresult_sql, consistent with how other DDL is handled.Fixes #343
Changes
fakesnow/cursor.py: newelifbranch alongside theSECREThandler forCREATE MACROtests/test_server.py:test_server_create_macroregression testTest plan
uv run pytest tests/test_server.py::test_server_create_macropasses🤖 Generated with Claude Code