Skip to content

test: fix operator precedence in manifest v2 assertions#3612

Open
anxkhn wants to merge 1 commit into
apache:mainfrom
anxkhn:patch-10
Open

test: fix operator precedence in manifest v2 assertions#3612
anxkhn wants to merge 1 commit into
apache:mainfrom
anxkhn:patch-10

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

Six assertions in tests/utils/test_manifest.py are written as:

assert x == a if format_version == 1 else b

In Python a conditional expression (a if cond else b) binds looser than ==, so this parses as:

assert (x == a) if (format_version == 1) else b

Both enclosing tests, test_write_manifest and test_write_manifest_list, are
@pytest.mark.parametrize("format_version", [1, 2]). For the format_version == 2 case each
statement therefore collapses to assert b, where b is a truthy constant (3, or the enum
member ManifestContent.DELETES). The v2 branch always passed without ever comparing the value
read back from the manifest, so the following reads were effectively unverified for v2:

  • manifest_entry.sequence_number
  • manifest_file.content, manifest_file.sequence_number, manifest_file.min_sequence_number
  • entry.sequence_number, entry.file_sequence_number

This is a masking / weak-test issue, not a production bug. Wrapping the right-hand side of each
assertion in parentheses restores the intended comparison for both format versions:

assert x == (a if format_version == 1 else b)

The values already present in the tests (3, ManifestContent.DELETES) are the correct
round-trip values; confirmed by temporarily injecting a wrong v2 value (999), which the old
shape accepted but the parenthesized shape correctly rejects.

Are these changes tested?

Yes, this change is itself a test-only strengthening.

  • pytest tests/utils/test_manifest.py -k "test_write_manifest or test_write_manifest_list"
    passes (14 passed) for both format_version 1 and 2.
  • To confirm the assertions now actually verify the v2 values, I temporarily set a v2 expected
    value to a deliberately wrong 999: with the original shape all v2 parametrizations still
    passed (the bug), and with the parenthesized shape the v2 cases fail with
    AssertionError: assert 3 == 999, i.e. the value is now checked. (The temporary edit was
    reverted; it is not part of this PR.)
  • make lint passes.

Are there any user-facing changes?

No. This only affects test code; there is no change to library behavior.

Six assertions in test_write_manifest and test_write_manifest_list used
the form `assert x == a if format_version == 1 else b`. Because a
conditional expression binds looser than `==`, Python parses this as
`assert (x == a) if (format_version == 1) else b`, so for the
format_version == 2 parametrization the whole statement collapses to
`assert b`, where b is a truthy constant (3, or ManifestContent.DELETES).
The v2 branch therefore always passed and never compared the actual
value read back from the manifest.

Wrap the right-hand side in parentheses so the conditional expression is
the comparison target. This restores verification of the v2
sequence_number, content, min_sequence_number, and file_sequence_number
on the manifest read/round-trip path. Test-only change; all parametrized
cases (v1 and v2) pass.

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant