fix: [SNOW-3480430] actionable error when a [connections] entry is not a table#2988
Draft
sfc-gh-olorek wants to merge 1 commit into
Draft
fix: [SNOW-3480430] actionable error when a [connections] entry is not a table#2988sfc-gh-olorek wants to merge 1 commit into
sfc-gh-olorek wants to merge 1 commit into
Conversation
…t a table `snow connection list` (and other commands that enumerate connections) crashed with `AttributeError: 'String' object has no attribute 'items'` when the `[connections]` section of `config.toml` contained an entry that was not a TOML table — for example, a stray scalar assignment like `default = "myconn"` sitting directly under `[connections]`. The alternative (config_ng) provider already silently filters non-dict entries, but the legacy provider passed them straight into `ConnectionConfig.from_dict`, which exploded on `.items()`. Instead of silently skipping (which could hide connections the user actually wanted), validate each entry and raise a `ClickException` that names the offending entry and shows the correct `[connections.<name>]` form. Falling back to a clear error matches the existing "Configuration file seems to be corrupted" pattern elsewhere in `config.py`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-review checklist
Changes description
Fixes #2954 (SNOW-3480430).
snow connection list(and other commands that enumerate connections) crashed withAttributeError: 'String' object has no attribute 'items'when the[connections]section of
config.tomlcontained an entry that was not a TOML table. The canonicalcause is a scalar assignment directly under
[connections], e.g.The legacy config provider iterates over each entry in the
[connections]sectionand passes the raw value to
ConnectionConfig.from_dict, which assumes a dict andcalls
.items(). For the scalar"conn"above, tomlkit returns atomlkit.items.String,and
.items()blows up with a bareAttributeError— no mention of which entry is wrongor how to fix it.
Fix
In
LegacyConfigProvider.get_all_connections, validate each entry and raise aClickExceptionthat:[connections.<name>]form.I considered silently filtering non-dict entries (mirroring
AlternativeConfigProvider. _get_file_based_connections, which does exactly that), but silently skipping would hidea connection the user actually meant to define, and the user would have no idea why their
connection doesn't show up. An actionable error matches the existing "Configuration file
seems to be corrupted" pattern in
config.pyand is more useful.The check uses
isinstance(config, dict)—tomlkit.items.Tableis adictsubclass, sovalid connection tables pass through unchanged.
Testing
Added a regression test (
test_connection_list_reports_malformed_connection_entry) thatreproduces the exact config from the issue and asserts the command fails with a message
naming the entry and showing the correct form. Verified that the test fails on
mainwith the original
AttributeErrorand passes with this fix.