Skip to content

fix(config): environment overrides for every backend key; Cassandra refuses unknown keys - #546

Open
LeeroyHannigan wants to merge 13 commits into
mainfrom
fix/539-540-backend-config-sections
Open

LeeroyHannigan wants to merge 13 commits into
mainfrom
fix/539-540-backend-config-sections

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 892ac27d8 and d2084892b merge main (feat(wasm): [Add WebAssembly browser support for ExtendDB #1009 and fix(storage-cassandra): extenddb destroy removes only a deployment's own keyspaces #1173 among the new commits).
  • d3845c734 moves the inline test modules of crates/storage/src/config.rs and crates/storage-cassandra/src/config.rs into config/tests.rs and config/string_coerce_tests.rs beside the first and config/tests.rs beside the second. The production files are 428 and 322 lines.
  • 49345d3d0 keeps serde's own error for a native value that does not fit: invalid value: integer `-1`, expected a u32 or its string form in place of invalid u32 value "-1": invalid digit found in string. Scalar::visit_f64 is gone, since serde's default gives the same error.
  • fe7ed0f8e adds extenddb_storage::config::parse_table, which names the key on one line in front of the message on the serve path, with tests that parse the way the backends do. The four backends call it in place of their own try_into().map_err(...).
  • 9be09e206 corrects the admin guide: only the installed backend's table refuses an unknown key. It adds the upgrade manual entry with the rollback note.
  • 759072971 elides an unused lifetime that clippy::pedantic flagged.
  • c9498e893 escapes a newline or a quote in the quoted value of a bad string form. It adds a test that reaches visit_u64.
  • 6dac27b15 merges main at d3b2a41a7. fix(metrics): bound latency segment memory by summing into fixed time buckets #398 added its v1.1.0 entry to docs/manuals/07-upgrade-manual.md where this branch adds its own. The merge keeps both entries, main's first.

What

EXTENDDB__<SECTION>__<KEY> environment values arrive as strings. The config crate coerces the top-level sections. Each [storage.<backend>] table goes to the backend as raw TOML, where serde is strict about types. The PostgreSQL and MongoDB structs opted their numeric fields into string_coerce in #222. The SQLite and Cassandra structs did not, so EXTENDDB__STORAGE__SQLITE__POOL_SIZE=4 failed with a type error. The three list keys (import.paths, export.paths, storage.cassandra.contact_points) had no environment form at all. [storage.cassandra] was also the one section without deny_unknown_fields, so a misspelled key there left the default in force with no error.

  • A list key accepts an array or one comma-delimited string: EXTENDDB__IMPORT__PATHS="/data/in,/data/shared". The string form trims each item and drops empty items, so an empty variable is an empty list. An array in the file keeps its items as written. The string form has no escape, so an item that contains a comma can only be written as an array. The file also accepts the string form for these keys, since the deserializer cannot tell a file value from a variable.
  • storage.sqlite.pool_size, storage.cassandra.replication_factor and storage.cassandra.max_connections accept their string form, as the PostgreSQL and MongoDB fields already did. String fields are not coerced: a password of "12345" stays a string and a bare 12345 is still a type error.
  • The scalar coercion helper is a serde visitor instead of an untagged enum. A bad string fails with the value quoted: invalid u32 value "four": invalid digit found in string. A native value that does not fit keeps serde's own error: invalid value: integer `-1`, expected a u32 or its string form, invalid type: boolean `true`, expected a u32 or its string form, invalid type: floating point `4.0`, expected a u32 or its string form. The untagged enum reported data did not match any variant of untagged enum MaybeString for every PostgreSQL and MongoDB field since [Bug] Environment-variable overrides for numeric and boolean config fields are deserialized as strings #222.
  • extenddb_storage::config::parse_table deserializes a backend's table and names the key on one line in front of the message: Failed to parse sqlite config: pool_size: invalid u32 value "-1": invalid digit found in string. Before, serve printed the key on a second line under the message, as toml's in `pool_size` . The SQLite, Cassandra, PostgreSQL and MongoDB backends call this one function. The init command's own Cassandra config parser does not change.
  • [storage.cassandra] refuses unknown keys like every other section, with the key named: Failed to parse cassandra config: unknown field `replication_factr`, expected one of `contact_points`, `username`, `password`, `keyspace_prefix`, `replication_factor`, `datacenter`, `max_connections` . The init template, the Cassandra test runner's config and the CI workflow write only keys the struct has. A file init wrote keeps starting. A hand-edited unknown key now stops serve, verify, migrate and init with the key named. So does an EXTENDDB__STORAGE__CASSANDRA__<KEY> variable the struct does not have. The upgrade manual has the entry and the rollback note.
  • The Cassandra backend's table deserializer is a named config::deserialize_config, as in the SQLite backend, so the tests exercise the entry point serve uses.
  • The admin guide, extenddb.sample.toml and the init template show the list form. The admin guide states that every section and the installed backend's table refuse an unknown key. It states that [storage] itself reads only backend and the installed backend's section. A misspelled key directly under [storage] is not read and raises no error. Neither is a table for a backend the binary does not install (pre-existing, outside this change).
  • The config crate's test module moved to crates/config/src/tests.rs. The test modules of crates/storage/src/config.rs and crates/storage-cassandra/src/config.rs moved to config/tests.rs and config/string_coerce_tests.rs beside the first and config/tests.rs beside the second. Each production file stays under 600 lines.

Why

Closes #539
Closes #540

An operator who sets EXTENDDB__STORAGE__SQLITE__POOL_SIZE or EXTENDDB__STORAGE__CASSANDRA__CONTACT_POINTS got a type error, and a misspelled Cassandra key ran with the default in force.

Conflicts with open PRs

Not in this change

An empty contact_points variable parses to an empty list, and session creation refuses it with No contact points configured, the same as contact_points = [] today. A relative item in paths (EXTENDDB__IMPORT__PATHS=data/in, or paths = ["data/in"] in the file) resolves against the working directory, as the array form always did. Where that is in daemon mode is #714. The init command's --cassandra-contact-points comparison splits on commas without trimming. Environment variables do not apply to init, and the array form does not change, so that code stays as it is. The configuration reference on #537 states the previous limitation (scalar keys only) in its sample header, generator, generated page and admin guide. That is how the code on that branch behaves. Whichever of the two merges second changes those four places to the list form and regenerates docs/configuration.md with npm run gen:config.

Testing done

Fourteen new tests: 5 in extenddb-storage, 4 in extenddb-storage-cassandra, 2 in extenddb-storage-sqlite, 3 in extenddb-config. Each attribute the change adds has a test that fails with it removed. The attributes: deny_unknown_fields on Cassandra, the list coercion on contact_points and on paths, the numeric coercion on SQLite pool_size, Cassandra replication_factor and max_connections, and the split character. The tests assert each error message by equality on the full text, in one data table per set of rows. The six wrong-type rows run through toml::from_str and through parse_table, which adds the key. The SQLite and Cassandra tests go through deserialize_config, the entry point serve uses. The config crate's tests feed the environment source load uses from a map instead of the process environment.

Lib tests passed at d2084892b, by crate: extenddb-app 105, extenddb-config 28, extenddb-storage 295, extenddb-storage-cassandra 195, extenddb-storage-mongodb 190, extenddb-storage-postgres 87, extenddb-storage-sqlite 329. The MongoDB crate has 84 more that need a server, and SQLite 1 ignored. Two SQLite backup_catalog::write_lock_tests fail on the build host only, where the backup root sits under a directory owned by another user. They do not touch this change. At c9498e893, extenddb-storage alone gave 294 passed. The seven-crate run counts one more test, behind test-hooks. cargo fmt --check is clean, and both clippy commands of CI give no warning on the seven crates. cargo +1.91.1 check --all-targets on the seven crates passes. clippy::pedantic gives no warning on a line this PR adds. The four license notices files are current with serde_path_to_error as a direct dependency of extenddb-storage. Both Python suites collect.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a

Breaking changes

A [storage.cassandra] key the struct does not have now stops serve, verify, migrate and init with unknown field and the key named. That covers a hand-edited key and an EXTENDDB__STORAGE__CASSANDRA__<KEY> variable. Files init wrote carry only known keys. On rollback, the previous binary refuses a file that writes a list key as one string (expected a sequence). It also refuses one of the three numeric keys as a quoted number (invalid type: string "4", expected u32). Before a rollback, write those keys as an array or a bare integer again, and unset the matching EXTENDDB__ variables. A wrong value in a backend table gets its key in front on one line. Before, the key sat on a second line. The upgrade manual has the entry.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

…efuses unknown keys

`EXTENDDB__<SECTION>__<KEY>` values arrive as strings. The top-level
sections are coerced by the config crate, and each `[storage.<backend>]`
table is handed to the backend as raw TOML, where serde is strict about
types. The PostgreSQL and MongoDB structs opted their numeric fields into
`string_coerce` (#222); the SQLite and Cassandra structs did not, so
`EXTENDDB__STORAGE__SQLITE__POOL_SIZE=4` failed with a type error. The
three list keys (`import.paths`, `export.paths`,
`storage.cassandra.contact_points`) had no environment form at all.

- `string_coerce::string_list` deserializes a `Vec<String>` from an array
  or from one comma-delimited string; items are trimmed and empty items
  dropped, so an empty variable is an empty list. `import.paths`,
  `export.paths` and `contact_points` use it. An array in the file is
  taken as written. The string form has no escape, so an item containing
  a comma can only be written as an array; the file now also accepts the
  string form for these keys, since the deserializer cannot tell a file
  value from a variable.
- `storage.sqlite.pool_size`, `storage.cassandra.replication_factor` and
  `storage.cassandra.max_connections` use `string_coerce::u32`, matching
  the PostgreSQL fields. String fields are not coerced: a password of
  `"12345"` stays a string and a bare `12345` is still a type error.
- The scalar coercion is a serde visitor instead of an untagged enum. A
  native integer, boolean or string goes through `FromStr`; a float, array
  or table is a type error. A wrong-type or out-of-range value now fails
  with the value, the accepted type and the key named (`invalid u32 value
  "-1": ...`, `invalid type: floating point 4.0, expected a u32 or its
  string form`), where the untagged enum reported `data did not match any
  variant of untagged enum MaybeString` for every PostgreSQL and MongoDB
  field since #222.
- `CassandraStorageConfig` gains `#[serde(deny_unknown_fields)]`, the one
  section that lacked it, so `replication_factr = 3` or a key from another
  backend's section fails at startup with the key named instead of leaving
  the default in force. The `init` template, the Cassandra test runner's
  config and the CI workflow write only keys the struct has.
- The Cassandra backend's table deserializer is a named
  `config::deserialize_config`, as in the SQLite backend, so the tests
  exercise the entry point `serve` uses.
- `extenddb_config` builds its environment source in one place; the tests
  feed that source from a map instead of the process environment and
  check `import.paths` and `export.paths` from variables, an environment
  list replacing a file array, an empty variable giving an empty list, and
  that a `[storage.<backend>]` value from a variable reaches the table as
  a string. The crate's test module moves to `tests.rs` unchanged, keeping
  `lib.rs` under 600 lines.
- The admin guide, `extenddb.sample.toml` and the `init` template show the
  list form, and the admin guide states that every section and backend
  table refuses an unknown key, and that `[storage]` itself reads only
  `backend`.

Tests: 16 new, in extenddb-storage, extenddb-config, extenddb-storage-sqlite
and extenddb-storage-cassandra. Each attribute the change adds has a test
that fails with it removed.

Closes #539
Closes #540
LeeroyHannigan added a commit that referenced this pull request Oct 25, 2026
…s unknown keys

The sample file, the generator's intro paragraph, the generated page and
the admin guide said the list keys and the SQLite and Cassandra numeric
keys were file only, and that `[storage.cassandra]` was the one section
that accepted unknown keys. Both limitations are removed by #546, which
this branch now assumes. The four places state the list form
(`EXTENDDB__IMPORT__PATHS="/data/in,/data/shared"`, items trimmed,
empty items dropped, an item containing a comma written as an array)
and that every section refuses an unknown key with the key named.
`docs/configuration.md` is regenerated; `--check` passes.
LeeroyHannigan added a commit that referenced this pull request Oct 31, 2026
…s unknown keys

The sample file, the generator's intro paragraph, the generated page and
the admin guide said the list keys and the SQLite and Cassandra numeric
keys were file only, and that `[storage.cassandra]` was the one section
that accepted unknown keys. Both limitations are removed by #546, which
this branch now assumes. The four places state the list form
(`EXTENDDB__IMPORT__PATHS="/data/in,/data/shared"`, items trimmed,
empty items dropped, an item containing a comma written as an array)
and that every section refuses an unknown key with the key named.
`docs/configuration.md` is regenerated; `--check` passes.
@navareamol navareamol added the v1 Needed for the 1.0 release label Nov 3, 2026
@navareamol navareamol added this to the 1.0 milestone Nov 3, 2026
crates/storage-cassandra/src/config.rs keeps the replication_factor doc comment from main (#909) and the string deserializer from this branch.

This branch refuses unknown keys in [storage.cassandra]. The bootstrapper tests from main that parse the section init writes into CassandraStorageConfig pass on the merge.
crates/config/src/lib.rs keeps the environment(None) source of main (#1003) in load and load_builtin_defaults, in place of the environment_source() of this branch, which builds the same source.

extenddb.sample.toml keeps the two [auth.encryption] variable examples from main and the list key example from this branch.
…of main

Main (#1003) added environment(vars) to crates/config/src/lib.rs. It builds the EXTENDDB__ source with the __ separator, and vars replaces the process environment in tests. The merge keeps it in load and load_builtin_defaults.

This branch's environment_source() built the same source with no vars, and config_from in tests.rs added the map with .source(Some(env)). The commit deletes environment_source(), and config_from calls environment(Some(env)), so the tests still read the source that load uses.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every backend key the PR covers is read from the environment and used. On builds of this head and of main 89fc971:

  • SQLite POOL_SIZE=4 is used (pool_size 4 raised to 10), where main refuses invalid type: string "4".
  • Cassandra CONTACT_POINTS overrides a wrong file value and connects, MAX_CONNECTIONS=3 opens 15 connections to the node against 22 at the default, and REPLICATION_FACTOR=2 over a file value of 1 warns for both keyspaces. Main refuses all three from the environment.
  • PostgreSQL and MongoDB pool keys behave as on main.
  • import.paths and export.paths take the comma form with trimming and empty items dropped, an empty variable overrides the file, and the file string form works; main refuses every string form.
  • The environment wins over the file in every case tried, and a bad or empty value is refused with the value quoted.
  • A misspelled [storage.cassandra] key is refused with the key named by serve, verify, migrate and init, where main ignored it. Configs written by main's init start on this head for SQLite and for Cassandra with password auth, and every Cassandra key in the templates, docs, devtools, CI and tests at v0.1.15, v1.0.0 and the merge-base is a known field.
  • A password override with commas and spaces stays one string and connects, the unknown-key error names the key and never the value, and no secret field goes through the new coercion.

fmt, both clippy variants and the 1.91.1 MSRV check are clean, 2014 tests pass across the seven touched crates, CI is green on 59 checks, and 13 negative controls each fail their target tests.

I will approve once the wrong-type error names the key on the serve path, with a test that parses the way the backends do.

docs/manuals/07-upgrade-manual.md:1

Two upgrade notes are missing. A hand-edited unknown Cassandra key (replication_factr, pasword) or env var (EXTENDDB__STORAGE__CASSANDRA__KEYSPACE) starts on main and stops migrate and serve here, so the body's "no existing deployment file starts failing" holds for files the templates wrote. On rollback, the previous binary refuses a file that uses the new string form (expected a sequence in contact_points).

crates/storage-cassandra/src/config.rs:1

This file grows from 456 to 602 lines and crates/storage/src/config.rs from 427 to 623, past the 600-line limit the PR gives for moving the lib.rs tests. Their inline test modules can move out the same way.

Comment thread crates/storage/src/config.rs Outdated
/// the accepted type and the key in the message, so `pool_size = -1` in a
/// file reads the same as it did before the string form was accepted.
#[test]
fn native_wrong_type_errors_name_the_value_type_and_key() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR says a wrong-type error names the key, and on the serve path it does not. SQLite answers Failed to parse sqlite config: invalid u32 value "-1": invalid digit found in string, and PostgreSQL gives the same text or invalid type: floating point 10.0, expected a u32 or its string form. This test passes because it parses with toml::from_str, which adds the key; the backends parse their table with Table::try_into, which does not. Both messages improve on main's data did not match any variant of untagged enum MaybeString for PostgreSQL. A test that goes through try_into, and a key added to the message there, would make the claim hold.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in fe7ed0f. At a0b4d2a the serve path did carry the key, but on a second line under the text you quoted, as toml's in `pool_size` , and the test parsed with toml::from_str. extenddb_storage::config::parse_table now deserializes the table through serde_path_to_error and writes one line with the key in front. Measured through extenddb_config::load with the SQLite backend installed: Failed to parse sqlite config: pool_size: invalid u32 value "-1": invalid digit found in string, and for a native value Failed to parse sqlite config: pool_size: invalid value: integer `-1`, expected a u32 or its string form. An unknown or missing field keeps its message as it was. The SQLite, Cassandra, PostgreSQL and MongoDB backends call this one function. The SQLite and Cassandra tests go through deserialize_config and assert the full text by equality. The storage crate runs its six wrong-type rows through parse_table with the count: prefix. Each failed on the old call sites.

parse(&v.to_string(), self.what)
}

fn visit_i64<E: Error>(self, v: i64) -> Result<T, E> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A native boolean or negative number now reads as a bad string. pool_size = true gives invalid u32 value "true": invalid digit found in string, where main gave invalid type: boolean `true`, expected u32, and pool_size = -1 gives the same "invalid digit" text, where main gave invalid value: integer `-1`, expected u32. That is on SQLite and Cassandra. The test comment at :548 says -1 reads as before. Returning serde's own type error from visit_bool and value error from visit_i64 would keep the native wording.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 49345d3. visit_u64, visit_i64 and visit_bool still parse first, so string_coerce::bool keeps accepting a native boolean, and when the parse fails they return serde's own error for the value they saw. Measured on the serve path: pool_size = -1 gives Failed to parse sqlite config: pool_size: invalid value: integer `-1`, expected a u32 or its string form, pool_size = true gives Failed to parse sqlite config: pool_size: invalid type: boolean `true`, expected a u32 or its string form, and 4294967296 gives invalid value: integer `4294967296`, expected a u32 or its string form. The string form keeps invalid u32 value "-1": invalid digit found in string. visit_f64 is gone, since serde's default returns the same invalid type: floating point `4.0`, expected a u32 or its string form. TOML hands every integer to visit_i64, so c9498e8 adds a test that feeds 4294967296 through a u64 deserializer to reach visit_u64. The Scalar doc comment and the test comment you pointed at now say this. The six rows (-1, 4294967296, 4.0, true, [4], "-1") sit in one table asserted by equality on toml::de::Error::message, and the first, second and fourth rows failed at a0b4d2a.

}

fn visit_str<E: Error>(self, s: &str) -> Result<Self::Value, E> {
Ok(s.split(',')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A path with a comma in the string form becomes two roots. With EXTENDDB__IMPORT__PATHS=<dir>/a,b, main refused to start; this head enables import from <dir>/a and from a relative b, which resolve_roots creates (drwx------) under the server's working directory. paths = "/data/a,b" in the file does the same. The comma rule is documented, but a typo now widens the import and export allowlist instead of stopping startup. Refusing a relative item in the string form would keep the old failure for this case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No code change for this one. The array form has always accepted a relative item: paths = ["/data/a", "b"] on main creates b under the working directory through the same resolve_roots. So the string form adds no new case here, and EXTENDDB__IMPORT__PATHS=b would reach it without any comma. Refusing relative items in the string form only would make EXTENDDB__IMPORT__PATHS=data/in fail where paths = ["data/in"] starts. Where a relative root resolves in daemon mode is #714. This PR keeps the two forms equal and documents that an item containing a comma goes in an array.

```

A list key (`import.paths`, `export.paths`, `storage.cassandra.contact_points`) takes one comma-delimited string; items are trimmed and empty items dropped, so an empty variable is an empty list. An item that itself contains a comma can only be written as an array in the config file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A table for a backend this binary does not install is not read: the SQLite binary starts with [storage.postgres] bogus = 1 in the file and with EXTENDDB__STORAGE__CASSANDRA__BOGUS=1 set. "Every [storage.<backend>] table" can say the installed backend's table.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 9be09e2. The paragraph now reads: "Every [section] and the installed backend's [storage.<backend>] table refuse to start the server on a key they do not know, with unknown field and the key named, so a misspelled key is a startup error rather than a default silently in force. The [storage] table itself reads only backend and the installed backend's section: a misspelled key placed directly under [storage], and a table for a backend this binary does not install ([storage.postgres] under the SQLite binary), are not read and raise no error." The PR body says the same.

…s out

`crates/storage/src/config.rs` stood at 623 lines and
`crates/storage-cassandra/src/config.rs` at 602, past the 600-line limit
this branch applied to `crates/config/src/lib.rs`. The inline test
modules move out the same way: `config/tests.rs` and
`config/string_coerce_tests.rs` beside the storage crate's `config.rs`,
`config/tests.rs` beside the Cassandra crate's. Each body keeps its text
apart from the indentation. `config.rs` keeps `#[cfg(test)] mod <name>;`
in place of the block. The production files are 394 and 296 lines.
`Scalar` sent every native integer and boolean through the string parser,
so `pool_size = -1` failed with `invalid u32 value "-1": invalid digit
found in string` and `pool_size = true` with `invalid u32 value "true":
invalid digit found in string`, where main gave ``invalid value: integer
`-1`, expected u32`` and ``invalid type: boolean `true`, expected u32`` on
SQLite and Cassandra. The operator wrote an integer or a boolean, not a
string, and `-1` has no invalid digit.

`visit_u64`, `visit_i64` and `visit_bool` still parse first, so `bool`
accepts a native boolean and `u32` a native integer. When the parse fails
they return serde's own error for the value they saw: ``invalid value:
integer `-1`, expected a u32 or its string form``, ``invalid value:
integer `4294967296`, expected a u32 or its string form``, ``invalid type:
boolean `true`, expected a u32 or its string form``. The string form keeps
`invalid u32 value "-1": invalid digit found in string`.

`visit_f64` goes: serde's default returns the same ``invalid type:
floating point `4.0`, expected a u32 or its string form``.

The storage crate's tests assert these messages by equality on
`toml::de::Error::message`, in one table of six rows (`-1`, `4294967296`,
`4.0`, `true`, `[4]`, `"-1"`). They replace a test that matched substrings
and passed with either wording. The list test asserts its three messages
by equality too. The whole-float test goes: the table's `4.0` row and
`native_types_deserialize_unchanged` cover its two checks.
…rong

The backends hand their `[storage.<backend>]` table to serde as a
`toml::Table`, which has no source text to point at. Its error put the
key on a second line, so `serve` printed `Failed to parse sqlite config:
invalid u32 value "-1": invalid digit found in string` and then ``in
`pool_size` `` under it. The key was there, but not where a reader looks
for it. The test for the message parsed with `toml::from_str`, which
points at the source line instead.

`extenddb_storage::config::parse_table` deserializes the table through
`serde_path_to_error` and writes one line with the key in front:
`Failed to parse sqlite config: pool_size: invalid u32 value "-1":
invalid digit found in string`, `Failed to parse cassandra config:
contact_points[1]: invalid type: integer `1`, expected a string`. An
unknown-field or missing-field message names its key already and passes
through unchanged. The SQLite and Cassandra `deserialize_config` and the
PostgreSQL and MongoDB `storage_config` closures call it, so the four
copies of `try_into().map_err(...)` are one function. `serde_path_to_error`
was in `Cargo.lock` already through axum. The storage crate now names it
as a dependency, and the four license notices files stay current.

Tests parse the way the backends do and assert the full message by
equality. The storage crate runs the six rows of its table through
`parse_table` with the `count:` prefix, plus a missing field. The SQLite
test asserts the `pool_size = "four"` message. One Cassandra table holds
four refusals: a misspelled key, another backend's key,
`replication_factor = "three"`, a numeric password. It replaces three
tests that matched substrings and one `is_err()`. Each new assertion
fails on the old call sites, which gave the key on its own line.
… upgrade notes

The admin guide said that every `[storage.<backend>]` table refuses an
unknown key. `StorageConfig::deserialize` reads the installed backend's
table only: it takes `value.get(backend)` and hands that table to the
backend. The SQLite binary starts with `[storage.postgres] bogus = 1` in
the file and with `EXTENDDB__STORAGE__CASSANDRA__BOGUS=1` set. The
paragraph now says the installed backend's table. It also names two cases
that are not read and raise no error. One is a misspelled key directly
under `[storage]`. The other is a table for a backend the binary does not
install.

The upgrade manual gains a v1.1.0 entry. A hand-edited unknown
`[storage.cassandra]` key, or an `EXTENDDB__STORAGE__CASSANDRA__<KEY>`
variable the struct does not have, started v1.0.0 with the default in
force. It now stops `serve`, `verify`, `migrate` and `init` with the key
named. A wrong value in a backend table gets its key in front, on one
line. On rollback, the previous binary refuses a file that writes a list
key as one string or a numeric key as a quoted number. Those keys go back
to an array or a bare integer first.

Three statements of the first commit of this branch, c72a748, no longer
hold at this head. `extenddb_config` does not build its environment source
in one place of its own: a0b4d2a deleted `environment_source()`, and the
tests call the `environment(Some(env))` of main. The wrong-type example
reads `Failed to parse sqlite config: pool_size: invalid u32 value "-1":
invalid digit found in string`, with the key in front. A native `-1` gives
``invalid value: integer `-1`, expected a u32 or its string form``, not
the string parser's text. The admin guide states that every section and
the installed backend's table refuse an unknown key, not every backend
table.
`cargo clippy -- -W clippy::pedantic` flags `impl<'de, T> Visitor<'de>
for Scalar<T>` with `elidable_lifetime_names`: no method of the impl uses
`'de`, so it is `Visitor<'_>`. This was the one pedantic warning on a
line this branch adds. The other warnings in the touched files are on
lines of main.
Main gained a417b2f (#1173) while this round ran. It adds the keyspace
prefix folding to `crates/storage-cassandra/src/config.rs` and a test to
the inline test module that d3845c7 moved out. The production additions
of main stay in `config.rs`. The new test,
`a_keyspace_prefix_is_lower_cased_in_every_form_it_is_given`, goes into
`config/tests.rs` at the place main has it, with the same text.
…isit_u64

The string form's error quoted the value raw. A value can come with a
newline or a quote, from the file or from an EXTENDDB__ variable. Such a
value put a line break in the message, which took the key off the value's
line. The
value is now written with Debug formatting. Values such as "four", "-1" and
"" keep their quotes. A newline or a quote is escaped.

TOML hands every integer to visit_i64. So no test reached the visit_u64
mapping of 49345d3, and a mutant that refused every u64 passed the 293 lib
tests of extenddb-storage. The new test feeds 4294967296 through a u64
deserializer and compares serde's message by equality.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. d208489 addresses the two items in the review body and the approval condition.

Upgrade notes: 9be09e2 adds a v1.1.0 entry to docs/manuals/07-upgrade-manual.md. A hand-edited unknown [storage.cassandra] key, or an EXTENDDB__STORAGE__CASSANDRA__<KEY> variable the struct does not have, started v1.0.0 with the default in force. The entry says that it now stops serve, verify, migrate and init with the key named, and that files init wrote carry only known keys. On rollback, the previous binary refuses a list key written as one string (expected a sequence) or a numeric key as a quoted number (invalid type: string "4", expected u32). The entry tells the operator to put those keys back to an array or a bare integer first. The body states the same in place of its "no existing deployment file starts failing" sentence.

File sizes: d3845c7 moves the inline test modules out, as the branch did for crates/config/src/lib.rs. crates/storage/src/config.rs has config/tests.rs and config/string_coerce_tests.rs beside it, crates/storage-cassandra/src/config.rs has config/tests.rs. The production files are 428 and 322 lines after the merge of #1173, whose new test moved with the module.

The key on the serve path is in fe7ed0f, with the tests through deserialize_config (thread above). Native values keep serde's wording in 49345d3. 892ac27 and d208489 merge main.

docs/manuals/07-upgrade-manual.md conflicted. Main added the v1.1.0 entry
of #398 at the top of Behavior Changes by Release, where this branch adds
its own v1.1.0 entry. Both entries stay, main's first. No other file
conflicted, and main changed no other file that this branch changes.

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The items from the earlier review are resolved at c9498e8, on SQLite, PostgreSQL, Cassandra 4.1 with password auth and a one-node MongoDB 7 replica set, against main 3534c9e, each case twice.

  • A wrong-type value names its key on the serve path, on one line: Failed to parse sqlite config: pool_size: invalid u32 value "four": invalid digit found in string, and PostgreSQL pool_size = 10.0 answers pool_size: invalid type: floating point `10.0`, .... migrate, verify and Cassandra init --overwrite print the same, array items carry an index (contact_points[1]: ...), and unknown and missing field messages are unchanged. parse_table uses the deserializer the old try_into used, so the accepted values are the same.
  • Native values keep serde's class and value text: -1, true, 4294967296, 4.0 and [4] answer as on main with "or its string form" added, and an env value of a"b prints as "a\"b" and 4<newline>x as "4\nx", on one line. The string form alone gets the "invalid digit" text.
  • The upgrade manual's v1.1.0 entry quotes messages the binaries print, the production files are 428 and 322 lines after a pure move of the tests, and the admin guide's sentence holds: a [storage.postgres] table, a Cassandra env variable and a misspelled [storage] key are not read on the SQLite binary, and an unknown [storage.sqlite] key is refused by name.
  • Everything that worked at a0b4d2a still works: env and file pool sizes, connection strings and path forms on every backend, Cassandra CONTACT_POINTS (22 connections), MAX_CONNECTIONS=3 (15) and REPLICATION_FACTOR=2, MongoDB env pool keys and read concern, and main's keyspace prefix lower-casing through parse_table. No password reaches an error line. fmt, both clippy commands and the 1.91.1 check are clean, 2076 tests pass, and CI was green on 65 of 65 checks at c9498e8; 6dac27b merges main and carries the same change.

crates/storage/src/config.rs (parse_table)

Optional. Reverting the escaping from c9498e8 leaves every test in the six crates passing, and the PostgreSQL and MongoDB parse_table call sites from fe7ed0f have no test of their own (reverting either passes 87 and 190 lib tests); SQLite and Cassandra are covered. The PR body's count is 15 new tests, 6 in extenddb-storage.

LeeroyHannigan added a commit that referenced this pull request Nov 25, 2026
The sample header, the generator's intro paragraph and the admin guide
said that every key has an environment form. They said that a list key
takes a comma-delimited string. That is #546's change, which this branch
does not contain: at this head `EXTENDDB__IMPORT__PATHS=/data/in,/data/shared`
fails with `expected a sequence` and `EXTENDDB__STORAGE__SQLITE__POOL_SIZE=8`
with `expected u32`. The three places now say that scalar keys take the
environment form. The list keys and the numeric keys of `[storage.sqlite]`
and `[storage.cassandra]` are file only. Those are the sentences 7612ce3
replaced. `npm run gen:config` regenerates `docs/configuration.md`. #546
updates the text when it lands.

This branch has not been deployed

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

Labels

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[storage.cassandra] accepts unknown keys silently Environment overrides fail for list keys and the SQLite and Cassandra numeric keys

3 participants