Problem
test_round_trip_floating_point in TypeTestsVector never asserts, so the float, double and decimal vector round trips pass even when the values read back are wrong.
The test passes partial(pytest.approx, abs=1e-5) as the comparison callback:
|
def test_round_trip_floating_point(self): |
|
_almost_equal_test_fn = partial(pytest.approx, abs=1e-5) |
|
def _random_decimal(): |
|
return Decimal(random.uniform(0.0, 100.0)) |
|
|
|
# Max value here isn't really connected to max value for floating point nums in IEEE 754... it's used here |
|
# mainly as a convenient benchmark |
|
self._round_trip_test("float", partial(random.uniform, 0.0, 100.0), _almost_equal_test_fn) |
|
self._round_trip_test("double", partial(random.uniform, 0.0, 100.0), _almost_equal_test_fn) |
|
self._round_trip_test("decimal", _random_decimal, _almost_equal_test_fn) |
_round_trip_test calls that callback as test_fn(observed, expected) and discards its return value:
|
if use_positional_parameters: |
|
observed1 = self._get_row_prepared(2, table_name) |
|
for idx in range(0, 3): |
|
test_fn(observed1[idx], expected1[idx]) |
|
|
|
observed2 = self._get_row_simple(5, table_name) |
|
for idx in range(0, 3): |
|
test_fn(observed2[idx], expected2[idx]) |
The call becomes pytest.approx(observed, expected, abs=1e-5): expected is taken as rel, and the returned matcher is never compared with anything.
#1043 fixed the same pattern for timestamp only, because pytest 9 started rejecting relative tolerance for datetimes:
|
def _assert_almost_equal(observed, expected): |
|
# Datetimes support an absolute timedelta, not relative tolerance. |
|
assert observed == pytest.approx(expected, abs=timedelta(seconds=1), rel=None) |
Impact
A regression in float, double or decimal serialization inside a vector passes CI. This is the only integration test that round-trips these vector subtypes through a server.
Reproduction
With pytest 9.1.1:
from functools import partial
from decimal import Decimal
import pytest
f = partial(pytest.approx, abs=1e-5)
f(1.0, 50.0) # ApproxScalar, no AssertionError
f(Decimal("1"), Decimal("50")) # ApproxDecimal, no AssertionError
Expected behavior
The floating-point vector round trips fail when a value read back differs from the one written by more than the 1e-5 absolute tolerance. That tolerance holds for vector<float, 3>: the worst float32 rounding error for values in [0, 100) was about 3.8e-6 over 200,000 samples.
Acceptance criteria
- Replacing an expected value with a wrong one makes each of the
float, double and decimal round trips fail.
Notes
Related
Problem
test_round_trip_floating_pointinTypeTestsVectornever asserts, so thefloat,doubleanddecimalvector round trips pass even when the values read back are wrong.The test passes
partial(pytest.approx, abs=1e-5)as the comparison callback:python-driver/tests/integration/standard/test_types.py
Lines 1053 to 1062 in fe0f0c9
_round_trip_testcalls that callback astest_fn(observed, expected)and discards its return value:python-driver/tests/integration/standard/test_types.py
Lines 1037 to 1044 in fe0f0c9
The call becomes
pytest.approx(observed, expected, abs=1e-5):expectedis taken asrel, and the returned matcher is never compared with anything.#1043 fixed the same pattern for
timestamponly, because pytest 9 started rejecting relative tolerance for datetimes:python-driver/tests/integration/standard/test_types.py
Lines 1072 to 1074 in fe0f0c9
Impact
A regression in
float,doubleordecimalserialization inside a vector passes CI. This is the only integration test that round-trips these vector subtypes through a server.Reproduction
With pytest 9.1.1:
Expected behavior
The floating-point vector round trips fail when a value read back differs from the one written by more than the
1e-5absolute tolerance. That tolerance holds forvector<float, 3>: the worst float32 rounding error for values in[0, 100)was about3.8e-6over 200,000 samples.Acceptance criteria
float,doubleanddecimalround trips fail.Notes
_round_trip_testcallers passassertEqualor, since build(deps): remove vulnerable Python 3.9 resolutions #1043, an asserting helper; only the floating-point partial is affected.Related
timestampround trip a real assertion.