Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: config 0.14.0 only supports lowercase fields (regression since 0.13.4) #531

Open
vladgon opened this issue Feb 3, 2024 · 8 comments
Labels
bug good first issue Issues/Bugs that are rather easy to solve for new Rustaceans/Contributors help wanted

Comments

@vladgon
Copy link

vladgon commented Feb 3, 2024

Failed to deserialize camelcase fields for yaml file
https://github.com/vladgon/rust/blob/49854f6c3d02bf7ae4a8d123ac9ecfbbe3959a56/wspace/wg_util/src/common/config/model.rs#L24

#[derive(Deserialize, Serialize, Debug)]
#[allow(non_snake_case)]
pub struct Kafka {
    pub broker: String,
    pub topic: String,
    pub pollSleep: u64,  //<---
}

https://github.com/vladgon/rust/blob/49854f6c3d02bf7ae4a8d123ac9ecfbbe3959a56/wspace/wg_sample_app/resources/app_config.yaml#L9

kafka:
  broker: localhost:29092
  topic: rust
  pollSleep: 1000

https://github.com/vladgon/rust/blob/49854f6c3d02bf7ae4a8d123ac9ecfbbe3959a56/wspace/wg_util/src/common/config/app_config.rs#L73-L78

@polarathene
Copy link
Collaborator

Probably have to compare the crate version differences of dependencies? Unless it was an actual internal change introduced to config-rs (I recall some work was contributed to rework deserializing).

Is this specific to YAML only? Could you try it with a different config file type?


If it's specific to YAML, there is plans to change the crate used: #474

I'm hoping to have time next week to tackle that and related PRs.

@vladgon
Copy link
Author

vladgon commented Feb 3, 2024

Tested with toml file same issue, works with 0.13.4, fails with 0.14.0

Setting Tracing filter config wg_util=debug,server=debug
2024-02-03T17:19:42.381705Z DEBUG ThreadId(01) wg_util::common::config::rust_app: 29: Using config files: "/Users/vova/workspace/rust/wspace/wg_sample_app/resources/app_config.toml"    
thread 'main' panicked at wg_util/src/common/config/app_config.rs:77:82:
missing field `pollSleep`
stack backtrace:

@polarathene
Copy link
Collaborator

works with 0.13.4, fails with 0.14.0

Ok, awesome!

So now we know that it's not format specific, it's either due to a dependency update or something that changed in the actual config-rs code. That's a tricky one someone will need to invest time into to track down.

There is a 211 commit difference to wade through, although it's not that bad as I recall this project uses merge commits from PRs rather than squash, so the actual range should be less.

I am aware of an approach called a git bisect that performs builds on different commits until it finds the one where the breakage was introduced. I've not used this before and assume it'll know to only test against the merge commits in that range rather than partial series of commits from a PR. It'd do something like start halfway through that list and if it works properly, then tries the halfway point in that smaller range and so forth.

Alternatively you could look through the commit history manually and see if anything stands out.


At a guess if it's failing with the rename, it may fail at other serde attributes that worked previously, which should help narrow it down to commit range between releases for specific files instead 👍

In fact at a glance it could be this: #354

I assume that'd mean your field is already internally treated as pollsleep, hence the breakage.

The project also documents the change history with a changelog thanks to @matthiasbeyer , that should help a little due to the merge approach. Give that a look, there's some other changes that could have been the culprit doing similar transforms.


Once that's pinned down, then we'd need to assess the intended fix vs the breakage it introduced and if both can remain fixed or if one has to be preferred 🤷‍♂️

Either way, sounds like a new test case for the project 😅

@polarathene polarathene added help wanted good first issue Issues/Bugs that are rather easy to solve for new Rustaceans/Contributors labels Feb 3, 2024
@polarathene polarathene changed the title regression in version config = "0.14.0" works fine in "0.13.4" bug: config 0.14.0 only supports lowercase fields (regression since 0.13.4) Feb 3, 2024
@polarathene
Copy link
Collaborator

I updated the title, it's still based on an assumption but may be more descriptive of what the actual regression is.

@vladgon
Copy link
Author

vladgon commented Feb 3, 2024 via email

@jpmckinney
Copy link

Yes, I think #354 is the cause. I would also like to be able to read in keys that don't get lowercased.

primeos-work added a commit to primeos-work/butido that referenced this issue Feb 29, 2024
This reverts commit 2ec9497.

We do unfortunately have to downgrade since `config 0.14.0` [0] converts
all configuration keys to lowercase but some of our configuration keys,
e.g. the environment variables, are case sensitive.
More details are in the relevant upstream PR [1] that made the crate
case insensitive by converting all the keys to lowercase "internally"
and a new issue discussing this change/regression [2].
Unfortunately this wasn't really mentioned as a breaking change in the
upstream config-rs changelog so I missed it.
This fixes such errors:
```
Error: build command failed

Caused by:
    0: Checking allowed variable names
    1: Checking allowed variables for package tree 1.8.0
    2: Environment variable name not allowed: additional_make_flags
```

I didn't notice this regression at first as I relied on the tests but
they don't catch such errors yet. I'll try to add a test case for this
error and check the environment variables defined in `pkg.toml` files
during the loading of the repository (should yield better error messages
and we do want to verify **all** packages and during the loading of the
repository ("evaluation")).

[0]: https://github.com/mehcode/config-rs/blob/0.14.0/CHANGELOG.md#0140---2024-02-01
[1]: mehcode/config-rs#354
[2]: mehcode/config-rs#531
@max-m
Copy link

max-m commented Mar 6, 2024

I noticed this change the hard way as well, my service exploded because case sensitive keys were suddenly converted to lower case.
Part of my parsed config is a hash map with case sensitive keys that must be passed as is to a downstream service.

struct Settings {
  ...
  downstream_config: HashMap<String, serde_json::Value>,
  ...
}

With version 0.14.0 all the keys of that map are now lowercase.
As a workaround I’ve rolled back to 0.13.4 for now.

And now that I think about it, I suppose this was also the issue I had when I tried to add a struct to my config that had #[serde(rename_all = "camelCase")] set and it couldn’t deserialize the config because myKey was apparently not set, even though it was. 🤔

dzhou121 added a commit to lapce/lapce that referenced this issue Mar 26, 2024
Syntax colors are affected by this bug

mehcode/config-rs#531

where enumMember is lowercased when
parsing the config
ada-phillips added a commit to TheContrappostoShop/Odyssey that referenced this issue Apr 28, 2024
Revert config version to 0.13.4 until the case bug is resolved
mehcode/config-rs#531
@ada-phillips
Copy link

Chiming in to say that this bug impacted my project as well, and was unexpected to say the least. I support PR #543 and think that PR #354 probably wasn't the most appropriate fix to Issue #340. I would think a better solution would be to not lowercase environment variables either? I might take a deeper dive into Issue 340 if I have time this week.

ada-phillips added a commit to TheContrappostoShop/Odyssey that referenced this issue Apr 30, 2024
* api: GET /files includes dirs, GET metadata

Modify GET single file endpoint to use :file_path instead
of :file_name
Modify /print/start to use :file_path instead of :file_name
Modify GET /files response to also return directory vec,
allowing the UI to hit one endpoint for filescreen population
and eventual sorting/filtering
Add GET /files/:location/:file_path/metadata endpoint for getting
metadata for a single file

* api: Suppress warnings on build, let clippy handle it

* api: fix sl1 processing to account for relative paths

* api: revert config crate version

Revert config version to 0.13.4 until the case bug is resolved
mehcode/config-rs#531

* api: move file_path to query params for /file and /file/metadata

Move /files/:location/:file_path to /file with query params
to support file_path parameter with slashes
Move metadata endpoint to /file/metadata, with same query params
Rename location category param to location

* api: migrate start endpoint to query params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Issues/Bugs that are rather easy to solve for new Rustaceans/Contributors help wanted
Projects
None yet
Development

No branches or pull requests

6 participants