Python3.11: "glance-manage" crashes

Bug #1982426 reported by Cyril Roelandt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Undecided
Unassigned

Bug Description

Removing a lot of the output since Launchpad is not going to format it properly anyway:

$ glance-manage -h
...
argparse.ArgumentError: argument command: conflicting subparser: db_version

This happens because the argparse module became stricter in Python3.11 and prevents us from adding the same subparser twice:

$ cat parser.py
import argparse

parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(title='Commands')
subparsers.add_parser('foo')
subparsers.add_parser('foo')
subparsers.add_parser('bar')
parser.parse_args()

$ python3.10 parser.py
$ python3.11 parser.py
Traceback (most recent call last):
  File "/tmp/parser.py", line 6, in <module>
    subparsers.add_parser('foo')
  File "/usr/lib/python3.11/argparse.py", line 1197, in add_parser
    raise ArgumentError(self, _('conflicting subparser: %s') % name)
argparse.ArgumentError: argument {foo}: conflicting subparser: foo
$

Changed in glance:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to glance (master)

Reviewed: https://review.opendev.org/c/openstack/glance/+/850589
Committed: https://opendev.org/openstack/glance/commit/76abb227addf1ae44813527084d1ceb7f36af606
Submitter: "Zuul (22348)"
Branch: master

commit 76abb227addf1ae44813527084d1ceb7f36af606
Author: Cyril Roelandt <email address hidden>
Date: Thu Jul 21 00:16:20 2022 +0200

    glance-manage: fix crash under Python3.11

    In Python3.11, the argparse module became stricter. While the following
    code was fine in previous versions, it will now raise an
    argparse.ArgumentError because we added the same subparser twice:

    import argparse
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(title='Commands')
    subparsers.add_parser('foo')
    subparsers.add_parser('foo')
    subparsers.add_parser('bar')
    parser.parse_args()

    This mistake was silently ignore in Python3.10, which explains why this
    was never an issue for glance-manage.

    Closes-Bug: #1982426
    Change-Id: I3a88ab5d2e67a1553f03b0b8ba44efbef976ffb0

Changed in glance:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/glance 25.0.0.0b3

This issue was fixed in the openstack/glance 25.0.0.0b3 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.