Skip to content

Fix greedy capture of positional arguments when names are identical#154

Merged
sea-odoo merged 1 commit into
betafrom
fix-positional-greedy-capture
Apr 28, 2026
Merged

Fix greedy capture of positional arguments when names are identical#154
sea-odoo merged 1 commit into
betafrom
fix-positional-greedy-capture

Conversation

@sea-odoo
Copy link
Copy Markdown
Contributor

Why

When running an odev command with a positional argument (e.g., database) and an Odoo-specific flag that takes a value (e.g., -i hotel), argparse sometimes incorrectly captures the flag's value as another optional positional argument (e.g., addons).

odev has a mechanism to "rescue" these values and move them back to the unknown arguments list, but it fails when the captured value is identical to a previous positional argument (e.g., odev create hotel -i hotel).

This happens because _rescue_positional_from_unknown_flag used list.index(raw_val), which always returns the index of the first occurrence of raw_val in argv_list. In the case above, it returned the index of the database name hotel, which is NOT preceded by an unknown flag, so the rescue logic was skipped.

Fix

The fix consists in iterating over all occurrences of raw_val in argv_list and checking if any of them follow an unknown flag. If a match is found, that occurrence is rescued.

Verification

  • Reproduced the issue with a script and verified that the fix correctly rescues the second hotel.
  • Added unit tests covering identical names, different names, and regular positional use.

Assisted-by: gemini-3-flash noreply@google.com

When a positional argument matches the name of a previous positional
argument (like the database name) and follows an unknown flag, argparse
incorrectly captures it. odev's rescue mechanism failed in this case
because it used list.index(), which returned the first occurrence.

This commit updates _rescue_positional_from_unknown_flag to check all
occurrences of the value in the original arguments list.

Assisted-by: gemini-3-flash <noreply@google.com>
@sea-odoo sea-odoo force-pushed the fix-positional-greedy-capture branch from 247a5f4 to c59a270 Compare April 28, 2026 12:48
@sea-odoo sea-odoo merged commit 3f4498f into beta Apr 28, 2026
5 of 6 checks passed
@sea-odoo sea-odoo deleted the fix-positional-greedy-capture branch April 28, 2026 12:48
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