From 57d6374e6b63552c2a09deff68362a9ed2a62101 Mon Sep 17 00:00:00 2001 From: Gopesh Pandey Date: Tue, 20 Jan 2026 17:52:11 +0530 Subject: [PATCH 1/3] Skip empty configuration values when writing AWS CLI config --- awscli/customizations/configure/writer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awscli/customizations/configure/writer.py b/awscli/customizations/configure/writer.py index 4aedabc43792..864f11b27b27 100644 --- a/awscli/customizations/configure/writer.py +++ b/awscli/customizations/configure/writer.py @@ -197,6 +197,10 @@ def _insert_new_values(self, line_number, contents, new_values, indent=''): new_contents.append('%s%s = %s\n' % (subindent, subkey, subval)) else: + if value is None: + continue + if isinstance(value, str) and not value.strip(): + continue new_contents.append('%s%s = %s\n' % (indent, key, value)) del new_values[key] contents.insert(line_number + 1, ''.join(new_contents)) From 3fe3e58d8b4b3cf5d0259c5fffdafe3b110951de Mon Sep 17 00:00:00 2001 From: Gopesh Pandey Date: Tue, 20 Jan 2026 17:55:27 +0530 Subject: [PATCH 2/3] Add test to ensure empty config values are not written --- tests/unit/customizations/configure/test_writer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/unit/customizations/configure/test_writer.py b/tests/unit/customizations/configure/test_writer.py index 92fd0f477453..fe6875436006 100644 --- a/tests/unit/customizations/configure/test_writer.py +++ b/tests/unit/customizations/configure/test_writer.py @@ -369,3 +369,17 @@ def test_appends_newline_on_new_section(self): '[new-section]\n' 'region = us-west-2\n' ) + def test_writer_skips_empty_values(tmp_path): + from awscli.customizations.configure.writer import ConfigFileWriter + + config_file = tmp_path / "config" + writer = ConfigFileWriter() + + writer.update_config( + {"region": "", "__section__": "default"}, + str(config_file), + ) + + contents = config_file.read_text() + assert "region" not in contents + From f76d799cee9227e31d8d984f70fec0770b5f13df Mon Sep 17 00:00:00 2001 From: Gopesh Pandey Date: Tue, 20 Jan 2026 18:03:43 +0530 Subject: [PATCH 3/3] Fix test to follow unittest style for empty config values --- .../customizations/configure/test_writer.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/unit/customizations/configure/test_writer.py b/tests/unit/customizations/configure/test_writer.py index fe6875436006..5b3599ea86d8 100644 --- a/tests/unit/customizations/configure/test_writer.py +++ b/tests/unit/customizations/configure/test_writer.py @@ -369,17 +369,13 @@ def test_appends_newline_on_new_section(self): '[new-section]\n' 'region = us-west-2\n' ) - def test_writer_skips_empty_values(tmp_path): - from awscli.customizations.configure.writer import ConfigFileWriter - - config_file = tmp_path / "config" - writer = ConfigFileWriter() - - writer.update_config( - {"region": "", "__section__": "default"}, - str(config_file), - ) + def test_writer_skips_empty_values(self): + self.writer.update_config( + {'region': '', '__section__': 'default'}, + self.config_filename + ) + with open(self.config_filename, 'r') as f: + contents = f.read() + self.assertNotIn('region', contents) - contents = config_file.read_text() - assert "region" not in contents