Skip to content

Increase number of Ruff rules applied to this project #694

Open

Description

@koletzilla

Follow up of #391

#679 Introduced Ruff with a good amount of rules to check, but that list can be improved so more things get checked/validated. Adding a list sorted by how impactful would be the changes:

  1. RUF (Ruff-specific) — 10 violations. The highest-value item on the list: RUF012 flags mutable class defaults in dbt/adapters/clickhouse/column.py:13 and impl.py:68 — class-level dicts shared across all instances, a real shared-state bug class. Also cleans up 6 stale # noqa comments (auto-fixable) and 2 unused unpacked variables in tests.

  2. DTZ (flake8-datetimez) — 3 violations. Flags naive datetime calls, e.g. datetime.now() without tz in test_clickhouse_table_ttl.py:63. Timestamps compared against ClickHouse server time can silently diverge when the CI machine's timezone differs — the classic cause of flaky TTL tests. Tiny fix, real failure mode.

  3. PGH (pygrep-hooks) — 6 violations. All blanket # noqa comments without rule codes (in __init__.py, dbclient.py). A bare # noqa suppresses every future rule on that line, so bugs introduced there later go unseen. Cheap fix, prevents future blind spots.

  4. RET (flake8-return) — 8 violations. One substantive catch: RET503 at impl.py:119, a function that returns a value on some paths but implicitly returns None on others — a potential missing-case bug. The remaining 7 are stylistic.

  5. C90 (mccabe complexity) — 2 violations at the default threshold of 10. Restores the guardrail our old flake8 config had. At the previous max-complexity = 18 it passes with zero changes today — it purely prevents future complexity growth.

  6. SIM (flake8-simplify) — 11 violations. Readability: mostly SIM118 (key in dict.keys() → key in dict) in impl.py and tests. No bugs, but genuinely cleaner code.

  7. PT (flake8-pytest-style) — 13 violations. Test-suite conventions: parametrize argument types (PT007) and yield fixtures with no teardown (PT022). Worthwhile given how test-heavy this repo is, but purely conventional.

  8. C4 (comprehensions) — 14 violations. Unnecessary generators passed to set() and similar. Micro-performance and style only; auto-fixable with --unsafe-fixes.

  9. UP (pyupgrade) — 137 violations. Ranked low not because it's bad but because it's pure modernization (Optional[str] → str | None, etc.) with the largest diff. All auto-fixable.

  10. PERF — 3 violations. Least impact: try/except inside loops. Would likely need a # noqa more than a fix.

items 1–5 (29 violations, mostly small or auto-fixable) buy all the actual bug-catching; 6–10 are style and modernization we can adopt incrementally.

Ones I'd skip:

  • S bandit, 669 hits — almost all false positives from SQL string-building, which is inherent to an adapter.
  • PL pylint, 139 — mostly magic-number and argument-count pedantry.
  • TRY 39 — opinionated exception style that conflicts with the adapter's error-wrapping pattern.
  • ARG 69 — unused arguments that are actually required by dbt's adapter interface signatures.

Activity

  1. added
    enhancement
    on Jul 29, 2026
  2. humayun-1 commented on Nov 16, 2026

    @humayun-1

    Hi @koletzilla , I'd like to pick this up, starting with items 1-5 (RUF, DTZ, PGH, RET, C90) and leaving SIM, PT, C4, UP and PERF for follow-up PRs as you suggested.

    Most of the fixes are mechanical: specific codes on the bare noqas, ClassVar on the class-level lookup tables, explicit returns, and tz-aware datetimes in tests. get_clickhouse_cluster_name would get an explicit return None, since several macros check is none. With the existing E/F rules on as well it comes to 24 findings rather than 29, since most of the RUF100 hits go away.

    A few questions before I open the PR:

    1. Is max-complexity = 18 (the old flake8 value) OK? At the default 10, _check_lightweight_deletes and s3source_clause would need a refactor or a noqa.
    2. Selecting all of RUF also pulls in RUF005, and DTZ001 flags test datetimes that are naive on purpose, so some open PRs (Execute v1 integration tests with v2 binary #717, fix(microbatch): filter Date event_time columns without a string cast #759) would start failing lint after a rebase. Would you prefer a per-file ignore for DTZ001 under tests/, or picking specific RUF rules instead of the whole set?
    3. ClassVar on CONSTRAINT_SUPPORT doesn't match how BaseAdapter declares it in dbt-adapters. mypy here doesn't follow imports so it passes, but I can use a noqa with a note instead if you prefer.

    It's working locally (lint clean, unit tests and the touched integration tests passing on 26.3 and 26.10), so I can open it as soon as you're happy with the choices.

  3. koletzilla commented on Nov 16, 2026

    @koletzilla
    ContributorAuthor

    Hi @humayun-1, I'm not convinced by the approach you mentioned. Let's wait for other users responses on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions