Skip to content

Re-baseline fork onto upstream v0.51.1 + ClickHouse SETTINGS - #4

Open
topher200 wants to merge 1 commit into
upstream-v0.51.1-basefrom
add-clickhouse-settings
Open

Re-baseline fork onto upstream v0.51.1 + ClickHouse SETTINGS#4
topher200 wants to merge 1 commit into
upstream-v0.51.1-basefrom
add-clickhouse-settings

Conversation

@topher200

@topher200 topher200 commented Jul 23, 2026

Copy link
Copy Markdown

Issues addressed

This is a preview of the change I intend to force-push onto this fork's master.

Our fork was pinned to an old pypika commit whose setup.py parses the version with ast.Str (removed in Python 3.12+). Renovate builds the fork from source under Python 3.14, so any Renovate PR that regenerated a lockfile touching pypika failed to build.

Upstream pypika has since revived (v0.51.1) and fixed that. So we adopt upstream wholesale and re-apply the thing our fork added: ClickHouse SETTINGS clause support.

The patch

  • ClickHouseQueryBuilder.settings(**kwargs) builder, plus SETTINGS serialization folded into upstream's existing _apply_pagination override (upstream now uses it for LIMIT BY), so SETTINGS emits after LIMIT.
  • unit test for this change

Verification

Full suite green under Python 3.14 (upstream's v0.51.1 fixes the ast.Str crash):

$ uv run --python 3.14 --with parameterized python -m unittest discover -s pypika/tests
Ran 1099 tests in 0.053s
OK

Clean, uncached wheel build under Python 3.14 now succeeds (this was the Renovate failure).

Tested against the memfault monorepo

Overlaid this build onto the monorepo's env (non-destructively) and ran the full pypika-touching data layer (~26 test files): 810 passed, 3 skipped, 4 failed. SETTINGS renders identically and both .settings(join_use_nulls=1) call sites pass.

The 4 failures are all cosmetic and non-impactful: pypika v0.51.1 renders the NULL literal lowercase (ELSE null vs ELSE NULL) in some CASE expressions, which trips exact-string snapshot tests in test_device_vital_queries.py. null/NULL are case-insensitive in ClickHouse and Postgres, so the queries are functionally identical; we'll just regenerate those snapshots when re-pinning the monorepo.

CI

Lint and the full unit-test matrix pass. The upstream Type Check (mypy) job is disabled in this fork (if: false in ci.yml): it is red on upstream's own v0.51.1 release commit.

The plan after approval

Force-push add-clickhouse-settings:master (master becomes v0.51.1 + this patch), then re-pin the memfault monorepo's pyproject.toml / uv.lock to that commit.

Seeing the full force-push effect

This PR intentionally hides the upstream adoption. To see everything the force-push changes vs the current (old) master:

git diff master..add-clickhouse-settings

That diff is dominated by 3 years of upstream changes.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 30048771680

Coverage decreased (-0.007%) to 98.429%

Details

  • Coverage decreased (-0.007%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (26 of 27 lines covered, 96.3%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
pypika/dialects.py 19 18 94.74%
Total (2 files) 27 26 96.3%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 7956
Covered Lines: 7831
Line Coverage: 98.43%
Coverage Strength: 0.98 hits per line

💛 - Coveralls

@topher200
topher200 requested a review from biggerfisch July 23, 2026 22:18
@topher200
topher200 force-pushed the add-clickhouse-settings branch from 2406102 to cc9ecd7 Compare July 23, 2026 22:28
### Issues Addressed

Our pypika fork was pinned to an old commit whose `setup.py` parses the
version with `ast.Str`, removed in Python 3.12+. Renovate builds the
fork from source under Python 3.14, so any Renovate PR that regenerated
a lockfile touching pypika failed to build.

Upstream pypika has since revived (v0.51.1) and fixed that.

### Summary

Re-add the fork on a fresh base: add the `.settings()` builder to
`ClickHouseQueryBuilder`.

I disabled mypy because it's already red.

### Test Plan

- Ran the full suite under Python 3.14, all green:

\`\`\`
$ uv run --python 3.14 --with parameterized python -m unittest discover -s pypika/tests
Ran 1099 tests in 0.053s
OK
\`\`\`

- Confirmed a clean, uncached wheel build now succeeds under Python 3.14
  (the build that was failing for Renovate).

Resolves: PLAT-X
@topher200
topher200 force-pushed the add-clickhouse-settings branch from cc9ecd7 to 5cc586d Compare July 23, 2026 22:41
@topher200
topher200 marked this pull request as ready for review July 23, 2026 23:10

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5cc586d. Configure here.

Comment thread pypika/dialects.py

def _format_value(v: object) -> str:
if isinstance(v, str):
return f"'{v}'"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unescaped string setting values

Medium Severity

String values in the ClickHouse SETTINGS clause are wrapped in single quotes without escaping embedded apostrophes. That diverges from pypika’s usual literal formatting via format_quotes / ValueWrapper.get_formatted_value, so a setting value containing ' can yield invalid SQL when the query is rendered.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5cc586d. Configure here.

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.

3 participants