#37096: test_invalid_choice_db_option fails on Python 3.14.5+
-------------------------------------+-------------------------------------
Reporter: Kasey | Type: Bug
Status: new | Component: Core
| (Management commands)
Version: dev | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
On Python 3.14.5+,
`admin_scripts.tests.CommandDBOptionChoiceTests.test_invalid_choice_db_option`
fails with:
{{{
AssertionError: "Error: argument --database: invalid choice: 'deflaut',
maybe you meant 'default'\? \(choose from default, other\)" does not match
"Error: argument --database: invalid choice: 'deflaut', maybe you meant
'default'? (choose from 'default', 'other')"
}}}
== Cause ==
CPython 3.14.5 restored quoting of choice values in argparse's "invalid
choice" error messages via [https://github.com/python/cpython/pull/149385
cpython#149385] (3.14 backport of
[https://github.com/python/cpython/pull/130751 cpython#130751], tracked in
[https://github.com/python/cpython/issues/130750 cpython#130750]). The
`choices` formatter changed from:
{{{#!python
'choices': ', '.join(map(str, action.choices)) # 3.14.0–3.14.4
}}}
to:
{{{#!python
'choices': ', '.join(repr(str(choice)) for choice in action.choices) #
3.14.5+
}}}
so the message goes from `(choose from default, other)` to `(choose from
'default', 'other')`.
The `PY314` branch of the test (added in commit
[https://github.com/django/django/commit/b1a65eac7c b1a65eac7c], fixing
#36321) expected the unquoted form. The pre-3.14 branch already handles
both forms via `'?default'?, '?other'?`; aligning the `PY314` branch with
the same pattern fixes the test on all Python 3.14.x releases.
== Scope ==
`main` only. `stable/6.0.x` and `stable/5.2.x` are unaffected — neither
branch enables `suggest_on_error` (added in #36321 on `main`), and both
already use the flexible `'?default'?, '?other'?` pattern.
== Patch ==
Patch ready (one-line test regex fix). PR link will follow in a comment
once the ticket is accepted.
--
Ticket URL: <https://code.djangoproject.com/ticket/37096>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019e1a9aba4d-26e80f00-a315-4584-be47-37615db854e9-000000%40eu-central-1.amazonses.com.