Skip to content

fix(tar): drop truthy-string default on store_true argparse flags#1065

Merged
cgrindel merged 1 commit into
bazelbuild:mainfrom
ashi009:preserve-flag-default
May 14, 2026
Merged

fix(tar): drop truthy-string default on store_true argparse flags#1065
cgrindel merged 1 commit into
bazelbuild:mainfrom
ashi009:preserve-flag-default

Conversation

@ashi009
Copy link
Copy Markdown
Contributor

@ashi009 ashi009 commented May 13, 2026

The --preserve_mode and --preserve_mtime flags in pkg/private/tar/build_tar.py were declared with default='False' (a string, which is truthy) combined with action='store_true'. When the flags are not passed, options.preserve_mode / options.preserve_mtime end up as the string 'False' rather than the boolean False — truthy under any natural truthy check.

Dropping default='False' is sufficient: action='store_true' already defaults to boolean False on its own.

Fixes #1064

The `--preserve_mode` and `--preserve_mtime` flags in
`pkg/private/tar/build_tar.py` were declared with `default='False'` (a
string, which is truthy) combined with `action='store_true'`. When the
flags are not passed on the command line, argparse uses the default
verbatim instead of the boolean `False` that `store_true` would produce,
so `options.preserve_mode` and `options.preserve_mtime` end up as the
string `'False'` — truthy under any natural truthy check.

rules_pkg's own use happens to be safe because the check is
`if self.preserve_mode is True`, but the typo is a foot-gun for anyone
copying the pattern.

Drop the bogus default — `action='store_true'` already defaults to
boolean `False`.

Fixes bazelbuild#1064
@ashi009 ashi009 requested review from aiuto and cgrindel as code owners May 13, 2026 10:22
@cgrindel cgrindel merged commit 22b54a3 into bazelbuild:main May 14, 2026
6 checks passed
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.

argparse: --preserve_mode / --preserve_mtime have a truthy string default

2 participants