Skip to content

Throw BAD_ARGUMENTS for duplicate key-value argument in object storage table functions - #107670

Merged
fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-s3-duplicate-kv-arg-bad-arguments-104267
Jun 17, 2026
Merged

fm4v merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-s3-duplicate-kv-arg-bad-arguments-104267

Conversation

@groeneai

@groeneai groeneai commented Jun 16, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed s3 and other object storage table functions throwing LOGICAL_ERROR instead of BAD_ARGUMENTS when a key-value argument is duplicated, e.g. s3('http://...', format = 'CSV', format = 'TSV').

Description

Closes #104267

A duplicated key-value argument is user input, but parseKeyValueArguments threw LOGICAL_ERROR, which aborts debug builds and is treated as critical by stress/fuzzer checks. Changed it to BAD_ARGUMENTS, matching the sibling validations in the same function. The helper is shared by the s3 table function and the S3-on-disk path, so both are covered.

Version info

  • Merged into: 26.6.1.914

…e table functions

A duplicated key-value argument such as
s3('http://...', format = 'CSV', format = 'TSV') is user-controlled input,
but parseKeyValueArguments threw LOGICAL_ERROR on the duplicate-key emplace.
LOGICAL_ERROR aborts debug builds and is treated as a critical failure by
stress and fuzzer checks, so a user typo must not produce it.

Use BAD_ARGUMENTS instead, matching the sibling user-input validations in the
same function. The helper is shared by S3StorageParsedArguments::fromAST and
parseFromDisk, so both code paths are covered.

Closes: ClickHouse#104267

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. On a debug build, clickhouse local -q "SELECT * FROM s3('http://localhost:11111/foo', format = 'CSV', format = 'TSV')" aborts every time (exit 134, Logical error: 'Duplicate key value argument: format').
b Root cause explained? parseKeyValueArguments (src/Storages/ObjectStorage/Utils.cpp) inserts each KV arg into a map and, on a failed insert (duplicate key), threw LOGICAL_ERROR. The arguments are fully user-controlled, so a duplicate is user error; LOGICAL_ERROR aborts debug builds and is treated as critical by stress/fuzzer checks.
c Fix matches root cause? Yes. Changed the throw to BAD_ARGUMENTS, the same code used by the sibling user-input validations in this function (wrong arg count, non-string key). No symptom-guarding.
d Test intent preserved / new tests added? New stateless test 04338_s3_duplicate_key_value_argument_bad_arguments asserts the three issue repro queries return { serverError BAD_ARGUMENTS }.
e Both directions demonstrated? Yes. Without the fix (Build ID c11861d3) the test FAILs: the server aborts on LOGICAL_ERROR. With the fix (Build ID 8003d21e) it passes 10/10 with randomization.
f Fix is general, not a narrow patch? The helper parseKeyValueArguments is shared by S3StorageParsedArguments::fromAST (s3 table function) and parseFromDisk (S3-on-disk), so one change covers both. The separate getFromPositionOrKeyValue BAD_GET case noted in the issue is a different code site and out of scope here.

Session id: cron:clickhouse-worker-slot-2:20260616-202700

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii @scanhex12 — could you review? One-line change in parseKeyValueArguments so a duplicated key-value argument in s3(...) (and the shared S3-on-disk path) throws BAD_ARGUMENTS instead of LOGICAL_ERROR.

@fm4v fm4v added the can be tested Allows running workflows for external contributors label Jun 17, 2026
@fm4v fm4v self-assigned this Jun 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4939661]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
Hung check failed, possible deadlock found FAIL cidb IGNORED
BuzzHouse (amd_debug) ERROR IGNORED

AI Review

Summary

This PR changes duplicate key-value argument validation in parseKeyValueArguments from LOGICAL_ERROR to BAD_ARGUMENTS and adds a focused stateless regression for s3 argument parsing. I did not find a changed-line correctness, safety, or metadata issue that warrants an inline review comment.

Missing context / blind spots
  • ⚠️ The GitHub checks still show Bugfix validation (functional tests), Fast test, Build (arm_tidy), and Code Review as pending, and this checkout has no local build directory, so I did not independently execute 04338_s3_duplicate_key_value_argument_bad_arguments.sql. Completed CI would close this execution-evidence gap.
Final Verdict

Status: ✅ Approve. The code change matches the reported Bug Fix, and the added regression covers duplicated key-value arguments for format, credentials, and structure before network access.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.20% 85.10% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.50% 77.40% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on this PR. The red checks are all pre-existing infra/chronic failures, not caused by this change. The PR's own regression test 04338_s3_duplicate_key_value_argument_bad_arguments passes in every functional job it ran (debug/asan/tsan/msan, parallel and flaky-check, all OK/SKIPPED).

Per-failure disposition:

  • Stress test (amd_tsan) / "Hung check failed, possible deadlock found" - chronic trunk flake: 172 distinct PRs / 274 master hits in 30d. Tracked separately (shutdown-deadlock family).
  • BuzzHouse (amd_debug) - harness flake: runner aborts with a Python traceback (status.tsv FileNotFoundError class), not a server crash. Other BuzzHouse variants finished "Fuzzer exited with timeout" = success. Tracked in our PR Report fuzzer runner aborts instead of an opaque status.tsv FileNotFoundError #107676.
  • Bugfix validation (functional tests) - job-level infra markers (OOM in dmesg, Lost forever for SharedMergeTree, Lost s3 keys, S3_ERROR No such key, Exception in test runner): chronic, 478 hits / 115 PRs in 30d. No test-level FAIL tied to this diff.
  • CH Inc sync - CIDB log-export infra step, orthogonal to PR content.
  • Mergeable Check / PR - aggregators reflecting the above; no independent signal.

This is a one-line error-code fix (LOGICAL_ERROR -> BAD_ARGUMENTS for duplicate KV args in object-storage table functions). Ready for review.

@fm4v
fm4v added this pull request to the merge queue Jun 17, 2026
Merged via the queue into ClickHouse:master with commit db4c103 Jun 17, 2026
162 of 166 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate KV argument in s3(...) throws LOGICAL_ERROR instead of BAD_ARGUMENTS

3 participants