Skip to content

fix: handle CREATE MACRO in server mode to avoid ProgrammingError - #344

Closed
mdz wants to merge 3 commits into
tekumara:mainfrom
mdz:claude/goofy-sanderson-a4ffab
Closed

fix: handle CREATE MACRO in server mode to avoid ProgrammingError#344
mdz wants to merge 3 commits into
tekumara:mainfrom
mdz:claude/goofy-sanderson-a4ffab

Conversation

@mdz

@mdz mdz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • CREATE MACRO is DuckDB-only DDL that sqlglot parses as an opaque Command, so it matched none of the result_sql branches in FakeSnowflakeCursor._execute and left _last_sql as the raw DDL string.
  • Server mode calls DESCRIBE <_last_sql> unconditionally, so DESCRIBE CREATE OR REPLACE MACRO … hit DuckDB's parser and raised a ProgrammingError, even though the macro was created successfully.
  • Fix: add a branch in _execute that detects CREATE … MACRO (via regex on the opaque Command.expression) and assigns SQL_SUCCESS as the result_sql, consistent with how other DDL is handled.

Fixes #343

Changes

Test plan

  • uv run pytest tests/test_server.py::test_server_create_macro passes
  • Existing server tests unaffected

🤖 Generated with Claude Code

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 tekumara left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Just added a suggestion for a test more consistent with the existing tests

Comment thread tests/test_server.py Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tekumara
tekumara enabled auto-merge (squash) June 29, 2026 10:12
@tekumara
tekumara disabled auto-merge June 29, 2026 10:50
Comment thread tests/test_describe.py


def test_description_create_macro(dcur: snowflake.connector.cursor.DictCursor):
dcur.execute("create or replace macro inc(x) as (x + 1)")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@mdz

mdz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #350

@mdz mdz closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server mode raises ProgrammingError on CREATE MACRO despite creating the macro

2 participants