Repository navigation
Conversation
Boolean CLI parameters were registered with a bare store_true action, so the documented --no_capture_message_content flag was unrecognized and the implicit False default made an unset flag indistinguishable from an explicit False. - Register boolean flags with default=None so omission stays None - Register --no_<name> (store_false, same dest) for params with has_negation set in PARAMETER_CONFIG - Drop the now-dead skip-False-when-default-True special case in set_environment_from_cli_args; explicit False now exports 'false', omission exports nothing, and env vars still take precedence Fixes openlit#1962
Reviewer's GuideImplementationRegister boolean flags with explicit unset values and configured negation forms, and export explicit false values instead of suppressing them.
TestsAdd tests for positive, negative, and omitted boolean flags, environment propagation and precedence, and rejection of conflicting flags.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoFix negated boolean flags in the Python SDK CLI
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Linked issuesChecked at commit a9ff671 #1962 Bug: Python CLI rejects configured --no_capture_message_content option · 4 of 5 met
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="sdk/python/src/openlit/cli/main.py" line_range="69-79" />
<code_context>
- parser.add_argument(cli_arg, action="store_true", help=cli_help)
+ # default=None (instead of store_true's implicit False) so that an
+ # unset flag is distinguishable from an explicit False.
+ parser.add_argument(
+ cli_arg, action="store_true", default=None, help=cli_help
+ )
+ if config.get("has_negation"):
+ parser.add_argument(
</code_context>
<issue_to_address>
**Reject conflicting flags**
The issue requires rejecting commands that specify both positive and negative forms. The change registers both actions independently, so conflicting forms are accepted and the last one wins.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: sdk/python/src/openlit/cli/main.py:79
Code Review by Qodo
1.
|
Register the --<name>/--no_<name> pair in a mutually exclusive group so passing both exits with an argparse error instead of silently keeping the last one, as the issue's expected behavior requires.
|
Both review bots flagged that the positive and negative forms could be passed together, with the last one silently winning. The issue's expected behavior does require rejecting that combination, so the pair is now registered in a mutually exclusive group (a9ff671): passing both |
Fixes #1962
Problem
openlit-instrument --no_capture_message_contentfails witherror: unrecognized arguments, even thoughPARAMETER_CONFIGdocuments negation support viahas_negation: Truefor that parameter.Two root causes in
parse_arguments:store_trueaction, so the--no_<name>form is never registered at all.store_true's implicitFalsedefault makes an unset flag indistinguishable from an explicitFalse, which forced theskip False when config default is Truespecial case inset_environment_from_cli_args- and made it impossible to ever pass an explicitfalsefor a default-Trueparameter.Fix
default=None, so omission staysNoneand is distinguishable from an explicit value.has_negation: TrueinPARAMETER_CONFIGadditionally get a--no_<name>flag (store_false, samedest).set_environment_from_cli_argsis removed. Semantics are now uniform:--capture_message_content-> env var"true"--no_capture_message_content-> env var"false"Tests
New
sdk/python/tests/test_cli_args.py(6 tests):--no_capture_message_contentparses toFalse(previouslySystemExit 2)--capture_message_contentparses toTrueNone--no_exports"false"to the env varVerified red on current
main(5 of 6 fail), green with the fix. Also re-ran the existingsdk/python/tests/test_env_config.py: 18 passed / 25 errors both before and after this change (the 25 errors are pre-existing import-time failures in my sandbox due to missing optional instrumentation dependencies, not related to this change; CI covers the full environment).Summary by Sourcery
Fix boolean CLI configuration so negation flags are accepted and explicit values are propagated without overriding existing environment settings.
Bug Fixes:
--no_negation forms for documented boolean CLI parameters, including explicit false values.Enhancements:
Tests: