Skip to content

Fix deterministic fingerprints for set-valued arguments#1345

Open
mattfaltyn wants to merge 4 commits into
databrickslabs:mainfrom
mattfaltyn:agent/deterministic-set-fingerprints
Open

Fix deterministic fingerprints for set-valued arguments#1345
mattfaltyn wants to merge 4 commits into
databrickslabs:mainfrom
mattfaltyn:agent/deterministic-set-fingerprints

Conversation

@mattfaltyn

Copy link
Copy Markdown

Changes

  • Canonicalize set and frozenset rule arguments after recursive normalization by sorting on their JSON representations.
  • Preserve list and tuple order without directly comparing heterogeneous or nested values.
  • Add a regression test with controlled opposite set iteration orders and mixed nested values.

Linked issues

Resolves #1333

Tests

  • manually tested
    • 10 independent PYTHONHASHSEED values produced one fingerprint.
    • make fmt passed Black, Ruff, mypy, and Pylint (10.00/10).
  • added unit tests
    • make test: 1,447 passed.
  • added integration tests — not applicable; this is a pure normalization helper.
  • added end-to-end tests — not applicable.
  • added performance tests — not applicable.

Documentation and Demos

  • added/updated demos — not applicable; there is no user-facing workflow change.
  • added/updated docs — updated the normalizer docstring to describe canonical set ordering.
  • added/updated agent skills — not applicable.

@CLAassistant

CLAassistant commented Jul 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@mattfaltyn
mattfaltyn marked this pull request as ready for review July 19, 2026 07:11
@mattfaltyn
mattfaltyn requested a review from a team as a code owner July 19, 2026 07:11
@mattfaltyn
mattfaltyn requested review from pratikk-databricks and removed request for a team July 19, 2026 07:11
@ghanse
ghanse requested review from Copilot and ghanse July 20, 2026 16:32

@ghanse ghanse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Overall this LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes non-deterministic rule fingerprints caused by set/frozenset iteration order (and thus PYTHONHASHSEED), by canonicalizing set-valued arguments during normalization so equivalent rules always hash the same.

Changes:

  • Canonicalize set/frozenset normalization by sorting normalized elements using their JSON representations.
  • Preserve list/tuple ordering (no cross-type comparisons) while still recursively normalizing nested values.
  • Add a regression test that forces opposite iteration orders for a mixed/nested set and asserts equal fingerprints.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/databricks/labs/dqx/utils.py Updates normalize_bound_args to sort normalized set/frozenset values deterministically and updates the docstring accordingly.
tests/unit/test_rule.py Adds a focused unit test ensuring compute_rule_fingerprint is order-independent for set-valued arguments with nested/mixed values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add equivalence-to-plain-set and negative-case assertions to guard
against the custom subclass masking behavior and the sort collapsing
distinct inputs.

Co-authored-by: Isaac

@mwojtyczka mwojtyczka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - added a few more assertions to stregthen the tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved to Merge When PR is reviewed and approved. To be merged once all tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Rule fingerprints vary with PYTHONHASHSEED for set-valued arguments

5 participants