TestFixture.test_get_hashes fails in Python 3.12

Bug #2046220 reported by Thomas Goirand
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
oslo.versionedobjects
Fix Released
Undecided
Unassigned

Bug Description

Hi,

Building the python-oslo.versionedobjects package in Debian Sid, with Python 3.12 as available interpreter version (meaning the unit tests are run with 3.11 and 3.12), I get the below unit test failure:

======================================================================
FAIL: oslo_versionedobjects.tests.test_objects.TestFixture.test_get_hashes
oslo_versionedobjects.tests.test_objects.TestFixture.test_get_hashes
----------------------------------------------------------------------
testtools.testresult.real._StringException: Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/oslo_versionedobjects/tests/test_objects.py", line 611, in test_get_hashes
    self.assertEqual('1.6-fb5f5379168bf08f7f2ce0a745e91027',
  File "/usr/lib/python3/dist-packages/testtools/testcase.py", line 394, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/usr/lib/python3/dist-packages/testtools/testcase.py", line 481, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: !=:
reference = '1.6-fb5f5379168bf08f7f2ce0a745e91027'
actual = '1.6-33df6764eb28348018ac966b9697d855'

Given the comment of the unit test:

        # NOTE(danms): If this object's version or hash changes, this needs
        # to change. Otherwise, leave it alone.

I'm blacklisting the unit test in the package. However, it'd be nice to fix it ASAP upstream too.

Cheers,

Thomas Goirand (zigo)

Revision history for this message
James Page (james-page) wrote :

This is caused by a change in the representation of an OrderedDict @ Python 3.12:

< 3.12:

print(OrderedDict({1:2, 3:4}))
OrderedDict([(1, 2), (3, 4)])

>= 3.12:

print(OrderedDict({1:2, 3:4}))
OrderedDict({1: 2, 3: 4})

a subtle but important difference when calculating the signature of the objects.

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

Reviewed: https://review.opendev.org/c/openstack/oslo.versionedobjects/+/906306
Committed: https://opendev.org/openstack/oslo.versionedobjects/commit/fe10f4559b97164a6e5649af13f5dbd3a77ba99d
Submitter: "Zuul (22348)"
Branch: master

commit fe10f4559b97164a6e5649af13f5dbd3a77ba99d
Author: James Page <email address hidden>
Date: Mon Jan 22 17:08:52 2024 +0000

    fixture: Drop use of OrderedDict for Python compat

    Python >= 3.12 changes the string representation of an OrderedDict
    which changes the md5 digest of an object; this causes a regression
    on the test_get_hashes unit test on newer Pythons.

    Subclass OrderedDict to revert the change in __repr__ in order provide
    a represenation which is consistent across all supported Python versions.

    Closes-Bug: #2046220
    Change-Id: I9b0d9e7b501f3de425bc2c342f25b8ea2248da20

Changed in oslo.versionedobjects:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/oslo.versionedobjects 3.5.0

This issue was fixed in the openstack/oslo.versionedobjects 3.5.0 release.

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.