Skip to content

fix: [SNOW-3480430] actionable error when a [connections] entry is not a table#2988

Draft
sfc-gh-olorek wants to merge 1 commit into
mainfrom
proactive/SNOW-3480430-connection-list-non-dict
Draft

fix: [SNOW-3480430] actionable error when a [connections] entry is not a table#2988
sfc-gh-olorek wants to merge 1 commit into
mainfrom
proactive/SNOW-3480430-connection-list-non-dict

Conversation

@sfc-gh-olorek
Copy link
Copy Markdown
Contributor

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.
  • I've described my changes in the documentation.

Changes description

Fixes #2954 (SNOW-3480430).

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. The canonical
cause is a scalar assignment directly under [connections], e.g.

[connections]
default = "conn"          # <-- this line is the problem

[connections.conn]
account = "..."

The legacy config provider iterates over each entry in the [connections] section
and passes the raw value to ConnectionConfig.from_dict, which assumes a dict and
calls .items(). For the scalar "conn" above, tomlkit returns a tomlkit.items.String,
and .items() blows up with a bare AttributeError — no mention of which entry is wrong
or how to fix it.

Fix

In LegacyConfigProvider.get_all_connections, validate each entry and raise a
ClickException that:

  • names the offending entry, and
  • shows the correct [connections.<name>] form.

I considered silently filtering non-dict entries (mirroring AlternativeConfigProvider. _get_file_based_connections, which does exactly that), but silently skipping would hide
a 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.py and is more useful.

The check uses isinstance(config, dict)tomlkit.items.Table is a dict subclass, so
valid connection tables pass through unchanged.

Testing

Added a regression test (test_connection_list_reports_malformed_connection_entry) that
reproduces 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 main
with the original AttributeError and passes with this fix.

…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`.
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.

SNOW-3480430: snow connection list fails with AttributeError: \'String\' object has no attribute \'items\'

1 participant