Fix greedy capture of positional arguments when names are identical#154
Merged
Conversation
brinkflew
approved these changes
Apr 28, 2026
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>
247a5f4 to
c59a270
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When running an
odevcommand with a positional argument (e.g.,database) and an Odoo-specific flag that takes a value (e.g.,-i hotel),argparsesometimes incorrectly captures the flag's value as another optional positional argument (e.g.,addons).odevhas 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_flagusedlist.index(raw_val), which always returns the index of the first occurrence ofraw_valinargv_list. In the case above, it returned the index of the database namehotel, 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_valinargv_listand checking if any of them follow an unknown flag. If a match is found, that occurrence is rescued.Verification
hotel.Assisted-by: gemini-3-flash noreply@google.com