Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): inconsistent struct hash calculation between Java and Python #2108

Merged
merged 11 commits into from
Mar 22, 2025

Conversation

LouisLou2
Copy link
Contributor

What does this PR do?

Problem

The struct hash calculation implementations in Java and Python are inconsistent. When classinfo is None in the Python implementation, the method returns early without updating the hash value, whereas the Java implementation continues with a default hash value of 0.

Solution

Modified the visit_customized method in the Python implementation to initialize hash_value to 0 before checking if classinfo is None, ensuring the hash computation continues regardless of the classinfo status. This approach aligns with the Java implementation behavior.

Changes:

  • Initialize hash_value to 0 at the beginning of the method
  • Replace the early return with a conditional assignment to hash_value
  • Always call _compute_field_hash at the end of the method

Testing

Verified the fix by running the CrossLanguageTest.java tests that were previously failing due to this issue. The struct hash values now match between Java and Python implementations.

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

@LouisLou2 LouisLou2 requested a review from chaokunyang as a code owner March 19, 2025 05:05
@chaokunyang
Copy link
Collaborator

Code lint check failed, please use black to format _struct.py

Copy link
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

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

Looks great

@chaokunyang chaokunyang merged commit c9d1f46 into apache:main Mar 22, 2025
47 checks passed
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.

2 participants