Python3.10 error

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

Bug Description

tox -e py310 fails - Please see comment #1.

Revision history for this message
Corey Bryant (corey.bryant) wrote (last edit ):

The following issue is hit when running tests with 'tox -e py310':

{1} glance.tests.unit.common.test_property_utils.TestPropertyRulesWithRoles.test_property_protection_with_misspelt_operation [0.131982s] ... FAILED

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    Traceback (most recent call last):

      File "/usr/lib/python3.10/configparser.py", line 790, in get
    value = d[option]

      File "/usr/lib/python3.10/collections/__init__.py", line 982, in __getitem__
    return self.__missing__(key) # support subclasses that define __missing__

      File "/usr/lib/python3.10/collections/__init__.py", line 974, in __missing__
    raise KeyError(key)

    KeyError: 'read'

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

      File "/home/corey/pkg/yoga/upstream/glance/glance/tests/unit/common/test_property_utils.py", line 105, in test_property_protection_with_misspelt_operation
    self.assertRaises(exception.InvalidPropertyProtectionConfiguration,

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/testcase.py", line 467, in assertRaises
    self.assertThat(our_callable, matcher)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/testcase.py", line 478, in assertThat
    mismatch_error = self._matchHelper(matchee, matcher, message, verbose)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/testcase.py", line 530, in _matchHelper
    mismatch = matcher.match(matchee)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/matchers/_exception.py", line 104, in match
    mismatch = self.exception_matcher.match(exc_info)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/matchers/_higherorder.py", line 62, in match
    mismatch = matcher.match(matchee)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/testcase.py", line 457, in match
    reraise(*matchee)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/compat.py", line 27, in reraise
    raise exc_obj.with_traceback(exc_tb)

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/matchers/_exception.py", line 97, in match
    result = matchee()

      File "/home/corey/pkg/yoga/upstream/glance/.tox/py310/lib/python3.10/site-packages/testtools/testcase.py", line 1039, in __call__
    return self._callable_object(*self._args, **self._kwargs)

      File "/home/corey/pkg/yoga/upstream/glance/glance/common/property_utils.py", line 109, in __init__
    self._load_rules()

      File "/home/corey/pkg/yoga/upstream/glance/glance/common/property_utils.py", line 137, in _load_rules
    permissions = CONFIG.get(property_exp, operation)

      File "/usr/lib/python3.10/configparser.py", line 793, in get
    raise NoOptionError(option, section)

    configparser.NoOptionError: No option 'read' in section: '^[0-9]'

description: updated
Revision history for this message
Cyril Roelandt (cyril-roelandt) wrote :

Thanks for your report. There are actually two issues here: one with Python3.9 and one with our tests.

$ cat cfg
[^[0-9]]
create = fake-role
rade = fake-role
update = fake-role
delete = fake-role

$ cat cfg.py
import configparser
CONF = configparser.ConfigParser()
CONF.read('/tmp/cfg')
print(CONF.sections()[0])

$ python3.9 cfg.py
^[0-9
$ python3.10 cfg.py
^[0-9]

There was a bug in 3.9 preventing the name of the section from being properly read, and it was fixed in 3.10 (https://github.com/python/cpython/commit/1cc6769e4146951d47528a97e56ba1e8e9ee7fc1).

In our tests, with Python3.9:
- _load_rules calls self._compile_rule('^[0-9'))
- in _compile_rule, re.compile('^[0-9') fails, which raises exception.InvalidPropertyProtectionConfiguration and allows the test to pass

With Python3.10, _compile_rule does not fail, allowing to move further in _load_rules and hit CONFIGK.get, which fails.

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

Reviewed: https://review.opendev.org/c/openstack/glance/+/825027
Committed: https://opendev.org/openstack/glance/commit/800ba9645dc180f8be4ac68e231cd7b7c6e42716
Submitter: "Zuul (22348)"
Branch: master

commit 800ba9645dc180f8be4ac68e231cd7b7c6e42716
Author: Cyril Roelandt <email address hidden>
Date: Tue Jan 18 00:43:08 2022 +0100

    Fix tests on Python3.10

    Both test_property_protection_with_missing_operation and
    test_property_protection_with_misspelt_operation rely on a bug in Python
    3.9: the "]" character in a section name is not read, so section
    '^[0-9]' is read as '^[0-9'. This causes _compile_rule to fail and raise
    the exception the tests are expecting.

    In Python 3.10, this bug has been fixed and the exception is no longer
    raised. Instead, CONFIG.get() raises a NoOptionError in _load_rules,
    which is not caught.

    Closes-Bug: #1954321
    Change-Id: Ibce11ac002dc900299d478ea875797dd1f8df17e

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

This issue was fixed in the openstack/glance 24.0.0.0rc1 release candidate.

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.