Repository navigation
Fix NameError masking test_migration diagnostic on count mismatch - #105159
Conversation
The diagnostic branch in `test_storage_s3_queue/test_migration.py::test_migration`
referenced undefined variables `total_rows`, `count1`, `count2` in its assertion
f-string. When the inner wait loop timed out (count didn't converge in 50s),
Python raised `NameError` at f-string evaluation, masking what should have
been a clear convergence failure.
CIDB confirms 81 failures of this form over the last 90 days, with a sharp
spike to 32 hits on 2026-05-16 across every sanitizer build (`amd_msan`,
`amd_asan_ubsan/db disk/old analyzer`, `amd_tsan`, `amd_llvm_coverage`,
`arm_binary/distributed plan`). All hits are PR-only — `pull_request_number > 0`
across 6+ unrelated PRs.
The diagnostic also computed `expected_files` using a wrong file naming
pattern (`{files_path}/test_{x}.csv`) — the actual files use `{use_prefix}_{i}.csv`
where `use_prefix` advances through `["a","b","c","d","e"]` across each
`add_files_and_check` call, and `i` starts at the cumulative `start_ind`.
The resulting `missing_files` list would always report every expected file
as missing, even when convergence was correct.
This change:
- Computes `count1` and `count2` from per-node `SELECT count()` queries
(the variables the original author intended)
- Uses `expected_rows[0]` instead of the never-defined `total_rows`
- Drops the broken `expected_files`/`missing_files` calculation
- Reports `distinct files processed` from the existing `processed_files` list,
which is a useful proxy for diagnostic without the buggy naming logic
- Switches the `processed_files` query from `node` (last value from a for-loop)
to `node1` for clarity
Demonstration in both directions:
- Without fix: `NameError: name 'total_rows' is not defined`
- With fix: `AssertionError: Expected 1000 rows in total, got 300 on node1
and 200 on node2 (500), distinct files processed: 5`
CIDB reference (last seen 2026-05-16 06:55 UTC):
https://play.clickhouse.com/?user=play&query=SELECT+test_name%2C+check_name%2C+count%28%29+FROM+default.checks+WHERE+test_name+LIKE+%27test_storage_s3_queue%2Ftest_migration.py%25%27+AND+test_context_raw+LIKE+%27%25NameError%25%27+GROUP+BY+test_name%2C+check_name+ORDER+BY+count%28%29+DESC
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Pre-PR validation gate (worker session
Additional notes:
|
|
cc @kssenii @alexey-milovidov — could you review this? It fixes the NameError-masked diagnostic in |
|
Workflow [PR], commit [da6f3ae] Summary: ✅ AI ReviewSummaryThis PR fixes the failure diagnostic in Final VerdictStatus: ✅ Approve |
Configures ruff via [tool.ruff] in pyproject.toml and wires it into the existing style-test job in ci/jobs/check_style.py. The initial rule set is narrow on purpose - only rules whose every hit is a real bug or unreachable reference: - F402 import-shadowed-by-loop-var - F522/F523 unused .format args - F601 duplicate dict-literal keys - F632 is comparison with a literal - F811 redefinition of an unused name (silently shadowed tests, duplicate route handlers, etc.) - F821 undefined name (the PR #105159 class - undefined variable inside an f-string evaluated only on an error/diagnostic branch, masking the original failure with NameError) Stylistic rules (F401, F541, F841, F403, F405) are intentionally left off for follow-up cleanups so the initial signal is bug-class only. Bugs found and fixed by the initial run: F821 (same pattern as PR #105159): - ci/jobs/scripts/check_ci.py - commit_status_data referenced in an exception branch but never assigned - tests/fuzz/runner.py - PIPE referenced without `from subprocess import PIPE` - tests/integration/test_backup_restore_on_cluster_with_checksum_data_file_name/test.py - os.path.join with os not imported - tests/integration/test_database_iceberg/test.py - BASE_URL_DOCKER typo for BASE_URL - tests/integration/test_keeper_remove_acl/test.py - node_zk referenced in a finally cleanup that was unreachable; the bare except silently swallowed the NameError on every run - tests/integration/test_storage_delta_disks/test.py - missing `from helpers.config_cluster import minio_secret_key` F811 silently-shadowed tests (later def overwrites earlier): - test_disk_types::test_different_types - test_storage_s3::test_empty_file - test_executable_table_function - one of the two same-named functions renamed to test_executable_storage_* - test_storage_delta::test_partition_columns_3 - second def renamed to test_partition_columns_jumbled F811 dead route handler: - test_merge_tree_s3_failover endpoint had two `def fail_request`; the throttle one was unreachable, renamed to throttle_request F601 duplicate dict-literal keys with divergent values in test_storage_s3_queue/test_5.py - same setting specified twice with different values; cleaned up to make the intended value explicit F522/F523 .format-string drift - templates updated without dropping the corresponding args (test_jbod_ha, test_manipulate_statistics, test_mysql_protocol, test_storage_kafka, helpers/dictionary) F632 `assert error is ""` -> `==` in test_allow_feature_tier F402 loop variable named `field` shadowing `from dataclasses import field` in praktika/issue.py Plus auto-fixed duplicate imports across CI scripts and integration tests. Two cases use `# noqa: F821` for legitimate self-referential type annotations (TypeVar bound and nested dataclass forward reference) in praktika/utils.py and praktika/gh.py. Reference: #105159 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The diagnostic branch in
test_storage_s3_queue/test_migration.py::test_migrationreferenced undefined variablestotal_rows,count1,count2in its assertion f-string. When the inner wait loop timed out (count didn't converge in 50s), Python raisedNameErrorat f-string evaluation, masking what should have been a clear convergence failure.CIDB confirms 81 failures of this form over the last 90 days, with a sharp spike to 32 hits on 2026-05-16 across every sanitizer build (
amd_msan,amd_asan_ubsan/db disk/old analyzer,amd_tsan,amd_llvm_coverage,arm_binary/distributed plan). All hits are PR-only —pull_request_number > 0across 6+ unrelated PRs (none of which touch s3_queue), making this a developer-experience pain point.The diagnostic also computed
expected_filesusing a wrong file naming pattern ({files_path}/test_{x}.csv) — the actual files use{use_prefix}_{i}.csvwhereuse_prefixadvances through["a","b","c","d","e"]across eachadd_files_and_checkcall, andistarts at the cumulativestart_ind. The resultingmissing_fileslist would always report every expected file as missing, even when convergence was correct.This change:
count1andcount2from per-nodeSELECT count()queries (the variables the original author intended).expected_rows[0]instead of the never-definedtotal_rows.expected_files/missing_filescalculation.distinct files processedfrom the existingprocessed_fileslist as a useful proxy without the buggy naming logic.processed_filesquery fromnode(last value from thefor node in [node1, node2]loop above) tonode1for clarity.Demonstration in both directions:
NameError: name 'total_rows' is not definedAssertionError: Expected 1000 rows in total, got 300 on node1 and 200 on node2 (500), distinct files processed: 5CIDB reference: https://play.clickhouse.com/?user=play#U0VMRUNUIHRlc3RfbmFtZSwgY2hlY2tfbmFtZSwgY291bnQoKSBGUk9NIGRlZmF1bHQuY2hlY2tzIFdIRVJFIHRlc3RfbmFtZSBMSUtFICd0ZXN0X3N0b3JhZ2VfczNfcXVldWUvdGVzdF9taWdyYXRpb24ucHklJyBBTkQgdGVzdF9jb250ZXh0X3JhdyBMSUtFICclTmFtZUVycm9yJScgR1JPVVAgQlkgdGVzdF9uYW1lLCBjaGVja19uYW1lIE9SREVSIEJZIGNvdW50KCkgREVTQw==
Past related fix PRs: #97677, #93232.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.5.1.719