fix: escape single quotes in generated SQL for config values by arijitroy003 · Pull Request #808 · duckdb/dbt-duckdb · GitHub
Skip to content

fix: escape single quotes in generated SQL for config values - #808

Merged
jwills merged 4 commits into
duckdb:masterfrom
arijitroy003:fix/escape-single-quotes-in-config-values
Aug 3, 2026
Merged

jwills merged 4 commits into
duckdb:masterfrom
arijitroy003:fix/escape-single-quotes-in-config-values

Conversation

@arijitroy003

Copy link
Copy Markdown
Contributor

Minimal fix for config values containing single quotes (e.g., a secret/password with an apostrophe) breaking generated SQL.

Per the discussion on #795/#796/#797, this consolidates the escaping into a single PR with just the inline single-quote doubling — no identifier quoting, no helper functions, no behavior changes.

Changes:

  • secrets.py: escape quotes in secret values, map keys/values, list items, and scope values
  • credentials.py: escape quotes in attachment paths and option values
  • environments/init.py: escape quotes in setting values

Each change is a single .replace("'", "''") at the interpolation point.

@jwills

jwills commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

@arijitroy003

Copy link
Copy Markdown
Contributor Author

All four addressed plus the optional fix:

  1. Added escape_sql_string() in utils.py, used everywhere
  2. Replaced all inline chr(39) with the shared helper
  3. Added the missing motherduck.py site
  4. Added tests covering attach path, option values, secret types, and a live DuckDB round-trip
  5. Added len(stripped) >= 2 guard on the already-quoted branch

Lines are within 99 chars. Thanks for the detailed review!

@jwills

jwills commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

looks good-- running pre-commit run --all-files should fix the last linting thing (did we include that in the CONTRIBUTING.md guide?)

@jwills

jwills commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

@arijitroy003 Thanks for the fix. The only failing check is code-quality: reorder-python-imports wants escape_sql_string listed before SourceConfig / TargetConfig in dbt/adapters/duckdb/environments/__init__.py. Could you push that small import-order update and rerun the check?

@arijitroy003

Copy link
Copy Markdown
Contributor Author

@jwills
jwills merged commit c139518 into duckdb:master Aug 3, 2026
32 checks passed
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.

2 participants