{"id":5883,"library":"collate-sqlfluff","title":"Collate SQLFluff","description":"collate-sqlfluff is a fork of SQLFluff (the SQL Linter for Humans), maintained by the OpenMetadata community. It provides a modular, dialect-flexible, and configurable SQL linter and auto-formatter, designed particularly for ELT applications. It supports multiple SQL dialects (e.g., BigQuery, Snowflake, PostgreSQL) and templating languages like Jinja and dbt. The library frequently syncs with upstream SQLFluff, incorporating its features and adhering to its semantic versioning, while adding specific enhancements relevant to OpenMetadata's ecosystem.","status":"active","version":"3.5.2","language":"en","source_language":"en","source_url":"https://github.com/open-metadata/collate-sqlfluff","tags":["SQL","linter","formatter","code quality","OpenMetadata","dbt","Jinja","ELT"],"install":[{"cmd":"pip install collate-sqlfluff","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"collate-sqlfluff is a fork of sqlfluff and builds upon its core functionality. Upstream changes, breaking or otherwise, generally apply to this package.","package":"sqlfluff","optional":false}],"imports":[{"note":"Despite the package name being `collate-sqlfluff`, the main import path for its functionality is `sqlfluff`.","wrong":"import collate_sqlfluff","symbol":"sqlfluff","correct":"import sqlfluff"},{"note":"For advanced programmatic usage, Linter and FluffConfig classes can be imported from sqlfluff.core.","symbol":"Linter","correct":"from sqlfluff.core import Linter, FluffConfig"}],"quickstart":{"code":"import sqlfluff\n\nmy_bad_query = \"SeLEct *, 1, blah as fOO from mySchema.myTable\"\n\n# Lint the given string and return violations\nlint_result = sqlfluff.lint(my_bad_query, dialect=\"bigquery\")\nprint(\"Linting Results:\", lint_result)\n\n# Fix the given string and get a fixed string back\nfix_result = sqlfluff.fix(my_bad_query, dialect=\"bigquery\")\nprint(\"Fixed Query:\\n\", fix_result)","lang":"python","description":"This example demonstrates how to use the programmatic API to lint and fix a SQL string using the `sqlfluff` module. The `dialect` parameter is often crucial for accurate linting and fixing."},"warnings":[{"fix":"Review the upstream `sqlfluff` release notes and migration guides (e.g., for 3.x and 4.x) to adapt code and configurations.","message":"collate-sqlfluff closely follows upstream sqlfluff releases. Major version updates in sqlfluff (e.g., 2.x to 3.x, 3.x to 4.x) introduce breaking changes to the Python API, rule coding, configuration, and CLI behavior. For instance, `sqlfluff fix` defaults behavior changed in 3.x, and 4.x introduced optional Rust routines. Users should consult the upstream sqlfluff release notes for migration guides.","severity":"breaking","affected_versions":">=3.0.0 (mirroring upstream sqlfluff changes)"},{"fix":"Always use `import sqlfluff` when importing the library in Python code.","message":"Although the package name is `collate-sqlfluff`, the primary Python import statement to access its functionality is `import sqlfluff`. Attempting to `import collate_sqlfluff` will result in a `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that `templater` configuration is defined in a higher-level configuration file (e.g., in the project root or user home directory) and not in subdirectories where it will be ignored.","message":"collate-sqlfluff uses a hierarchical configuration system where local configuration files override global ones. However, the `templater` configuration option *cannot* be set in config files located in subdirectories of the working directory; it must be set at a higher level.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Exercise caution when granting edit access to SQL or configuration files containing templated code. Review templated SQL for malicious constructs, especially when sourcing from untrusted users or environments.","message":"When using Jinja or dbt templating with `collate-sqlfluff`, macros within the SQL can potentially execute arbitrary code. While `sqlfluff` employs Jinja2's `SandboxedEnvironment` for some protection, users with edit access to SQL or configuration files should be aware of potential security implications, as some macros (e.g., dbt `run_query`) might execute arbitrary SQL.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}