Skip to content

fix: use ArgMatches::value_source to distinguish user-provided from default#25

Open
amaksimo wants to merge 1 commit into
mainfrom
add-regression-tests-for-arg-validation
Open

fix: use ArgMatches::value_source to distinguish user-provided from default#25
amaksimo wants to merge 1 commit into
mainfrom
add-regression-tests-for-arg-validation

Conversation

@amaksimo
Copy link
Copy Markdown
Contributor

@amaksimo amaksimo commented May 6, 2026

Summary

Root-causes the class of bug fixed in efe936b (removing default_value = "\"" from --quote). That fix was correct but fragile: it only addressed the one flag, and imposed an invisible "don't add defaults to SourceArgs" restriction that no one would know about.

This PR removes the restriction by fixing the underlying validation logic.

Before

validate_delimited_options used source.field.is_some() to mean "user passed this flag". For an Option<String> with a default_value, clap populates the field — so .is_some() is true even when the user passed nothing. That's what caused parquet loads to fail when --quote had a default.

After

Uses ArgMatches::value_source(..) == ValueSource::CommandLine, which is clap's canonical answer to "did this flag appear on argv?". Defaults are now safe to add on any SourceArgs field without breaking validation.

  • Introduces DELIMITED_OPTION_FLAGS so registering a new delimited option is a single-line change in one place.
  • Matrix test covers {csv, tsv, parquet} × each delimited flag.
  • defaults_do_not_count_as_user_provided pins the core invariant at the validation function, independent of which fields happen to carry defaults today.

Test plan

  • cargo fmt -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --bin aurora-dsql-loader — 3/3 pass
  • Regression check: temporarily added default_value = "\"" back to --quote; all tests still pass (the bug cannot be reintroduced via defaults). Reverted.

@amaksimo amaksimo force-pushed the add-regression-tests-for-arg-validation branch from 77f2d96 to 99e66f4 Compare May 6, 2026 21:04
@amaksimo amaksimo changed the title test: add regression guards for delimited-options validation fix: use ArgMatches::value_source to distinguish user-provided from default May 6, 2026
@amaksimo amaksimo force-pushed the add-regression-tests-for-arg-validation branch from 99e66f4 to c0acad0 Compare May 6, 2026 21:07
…efault

Root-causes the class of bug fixed in efe936b. Previously
validate_delimited_options used `source.field.is_some()` to mean "user
passed this flag", which silently breaks the moment any delimited field
gains a `default_value` — exactly what caused the parquet regression.

Switches the check to `ArgMatches::value_source(..) == CommandLine`,
which is clap's canonical "was this flag provided on argv?" query.
Defaults are now safe to add on any field without breaking validation.

- Adds `DELIMITED_OPTION_FLAGS` so adding a new delimited option is a
  single-line registration next to where it needs to be registered.
- Matrix test covers {csv, tsv, parquet} x each delimited flag.
- `defaults_do_not_count_as_user_provided` pins the core invariant at
  the validation function, independent of which fields happen to carry
  defaults today.

Verified by temporarily adding `default_value = "\""` back to --quote:
all tests still pass (the bug cannot be reintroduced via defaults).
@amaksimo amaksimo force-pushed the add-regression-tests-for-arg-validation branch from c0acad0 to 1609641 Compare May 6, 2026 21:11
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.

1 participant