Skip to content

feat: [SNOW-2457402] Unify encoding support in SnowCLI#2792

Open
sfc-gh-kolszewski wants to merge 17 commits intomainfrom
ko/SNOW-2457402-unify-encoding-support
Open

feat: [SNOW-2457402] Unify encoding support in SnowCLI#2792
sfc-gh-kolszewski wants to merge 17 commits intomainfrom
ko/SNOW-2457402-unify-encoding-support

Conversation

@sfc-gh-kolszewski
Copy link
Copy Markdown
Contributor

@sfc-gh-kolszewski sfc-gh-kolszewski commented Feb 27, 2026

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

See https://snowflakecomputing.atlassian.net/browse/SNOW-2683933

This change adds new encoding configuration section with following keys:

  • file_io - which controls the encoding used on file operations (read, write, open). Uses platform default if not set.
  • subprocess - which controls the encoding used on commands run with subprocess. Uses platform default if not set.
  • show_warnings - which controls whether a warning should be displayed if SnowCLI discovers encoding mismatch in the environment. True by default.

Encoding settings are read from the configuration by SecurePath's read_text, write_text and open methods. As such, most places in the code where SecurePath was not used for these purposes were refactored to use SecurePath. I did not apply this change where encoding was already explicitly set as 'utf-8'

The change should be transparent to Unix users. Windows users can expect the warning to be displayed.

@sfc-gh-kolszewski sfc-gh-kolszewski marked this pull request as ready for review March 4, 2026 14:55
@sfc-gh-kolszewski sfc-gh-kolszewski requested a review from a team as a code owner March 4, 2026 14:55
Copy link
Copy Markdown
Contributor

@sfc-gh-olorek sfc-gh-olorek left a comment

Choose a reason for hiding this comment

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

Three issues found during review — fixes committed on the branch.


DEFAULT_TIMEOUT = 30
DRIVER_PATH = Path(__file__).parent / "setup_driver.py.source"
DRIVER_PATH = SecurePath(__file__).parent / "setup_driver.py.source"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: DRIVER_PATH changed from Path to SecurePath, but DRIVER_PATH.read_text() at line 169 is called without the required file_size_limit_mb argument — this is a TypeError at runtime.

Since this is an internal bundled script with no encoding concern, reverting back to Path.

Comment thread tests/nativeapp/test_manager.py Outdated
feature_flag,
):
mock_get_config_value.return_value = feature_flag
mock_get_config_value.side_effect = [None, feature_flag]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fragile: side_effect = [None, feature_flag] is order-dependent. If any additional get_config_value call is added to the production code path (e.g. another encoding config read), the list shifts and the test silently returns wrong values.

Replacing with a function-based side_effect that matches on key name, so it's resilient to changes in the number of config reads.

def _read_config_file_toml() -> dict:
return tomlkit.loads(get_config_manager().file_path.read_text()).unwrap()
return tomlkit.loads(
SecurePath(get_config_manager().file_path).read_text(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TOML files are always UTF-8 by spec. Since SecurePath.read_text() now applies the user's file_io encoding setting, a user who configures file_io = "cp1252" would corrupt the CLI's own config file on re-read.

Same issue applies to _read_connections_toml and _update_connections_toml below.

Adding explicit encoding="utf-8" to all three functions.

sfc-gh-kolszewski and others added 17 commits April 15, 2026 13:21
… encoding

- Revert DRIVER_PATH from SecurePath back to Path: SecurePath.read_text()
  requires file_size_limit_mb which was not passed, causing a runtime crash.
  The bundled driver script has no encoding concern.
- Use function-based side_effect in test_manager.py instead of fragile
  ordered list [None, feature_flag] that breaks when config reads change.
- Always read/write TOML config files with encoding="utf-8" since TOML spec
  requires UTF-8. Prevents user's file_io encoding config from corrupting
  the CLI's own config and connections files.
@sfc-gh-olorek sfc-gh-olorek force-pushed the ko/SNOW-2457402-unify-encoding-support branch from 3a9a274 to 4ee3e72 Compare April 15, 2026 13:25
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.

2 participants