Skip to content

fix(snowflake): detect DDL statement verbs - #4210

Draft
yaxuanm wants to merge 1 commit into
langgenius:mainfrom
yaxuanm:fix/snowflake-ddl-statement-detection
Draft

yaxuanm wants to merge 1 commit into
langgenius:mainfrom
yaxuanm:fix/snowflake-ddl-statement-detection

Conversation

@yaxuanm

@yaxuanm yaxuanm commented Nov 4, 2026

Copy link
Copy Markdown

Summary

Snowflake SQL rejects valid DDL when its declared SQL type is CREATE, DROP, ALTER, or TRUNCATE. sqlparse classifies these verbs as Keyword.DDL, which the statement-type detector skips. For example, CREATE SCHEMA EXAMPLE_SCHEMA is incorrectly detected as SCHEMA.

Recognize DDL tokens and normalize compound tokens such as CREATE OR REPLACE to the leading verb. Keep existing validation and explicitly reject DROP USER, DROP ROLE, and ALTER USER, which were already listed as restricted operations in the recursive keyword check but were not reliably matched across separate tokens. Match dangerous operations and restricted DDL against a comment-stripped copy so line comments cannot bypass those checks; the executed SQL and existing injection/multiple-statement checks retain the original input.

Add regression tests for DDL variants, declared-type mismatches, restricted operations, multiple statements, and connector invocation. Bump the plugin version to 0.0.9; dependencies and uv.lock are unchanged.

Release Notes

  • Fix valid Snowflake DDL queries being rejected because the statement type was detected as the object type. This includes CREATE SCHEMA, CREATE OR REPLACE, secure views, and CREATE TABLE AS SELECT.
  • Preserve validation of restricted administrative operations and multiple SQL statements.

Change Type

  • Documentation / non-plugin change
  • Non-LLM plugin (tools, extensions, datasource, etc.)
  • LLM plugin

Screenshots / Videos

Not applicable. The regression is covered by executable parser and connector-invocation tests.

Version

  • Bumped top-level version in manifest.yaml (not the one under meta)
  • dify_plugin>=0.3.0,<0.11.0 is declared in pyproject.toml and locked in uv.lock

The existing dependency declaration is unchanged (dify_plugin>=0.9.0); the frozen lockfile resolves to SDK 0.10.2.

Testing

A clean environment was created with Python 3.12.14, matching the manifest's Python 3.12 runtime. Dependencies were installed with uv sync --frozen --all-groups from the existing lockfile.

  • uv run --frozen --with pytest python -m pytest -q: 84 passed, including the two existing OAuth cache tests. There are two SDK/gevent dependency warnings.

  • Regression demonstrated before the fix: CREATE SCHEMA EXAMPLE_SCHEMA, declared as CREATE, failed with detected as SCHEMA.

  • Valid CREATE SCHEMA, replace/secure views, and CTAS reach the mocked connector exactly once, return success, and close the connection. Rejected queries never open a connection. Line-comment DDL controls are covered, and the existing block-comment injection rejection is unchanged.

  • git diff --check passes. The plugin packages successfully with the Dify plugin CLI.

  • No live Snowflake statements or deployment changes were performed by this test suite.

  • Local deployment — Dify version: 1.7.0

  • SaaS (cloud.dify.ai)

This branch has not been deployed

No deployments
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.

1 participant