Fix Python tuple packing treating __eq__-None objects as NULL - #13967
Open
Divyansh151005 wants to merge 1 commit into
Open
Fix Python tuple packing treating __eq__-None objects as NULL#13967Divyansh151005 wants to merge 1 commit into
Divyansh151005 wants to merge 1 commit into
Conversation
Use identity for real None and only treat fdb.impl.Value objects that wrap None as null, so custom types that override __eq__ can no longer silently corrupt packed keys. Fixes apple#13267.
Divyansh151005
force-pushed
the
fix/python-tuple-none-identity-check
branch
2 times, most recently
from
August 29, 2026 18:16
9139512 to
aec3e6a
Compare
Contributor
|
I closed the justification over at #13267 as basically working as intended -- see the comment there. I was going to close this @Divyansh151005 but then asked the local LLM its opinion and it suggests:
The above I read as a mixed message over a small issue. Perhaps we should just close this out and figure more substantial or more straightforward items to work on. Happy to help. Thanks for contributing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #13267.
In
bindings/python/fdb/tuple.py,_encode(and_code_for) usedvalue == Noneto detect null tuple elements. That was intentional forfdb.impl.Valueobjects that wrapNone(they override equality), but it also meant any user-defined object whose__eq__returns true forNonewas silently packed as NULL (\x00) instead of raisingValueError. That is a silent key-corruption bug.Solution
Introduce
_is_null()that:Nonewith identity (is None).fdb.impl.ValuewrappingNoneas null. Those objects override__class__tobytes, soisinstance(value, bytes) and value == Nonematches them; realbytesare never equal toNone.__eq__to matchNone(they fall through to the existingValueError)._encodeand_code_forboth use this helper so packing and comparison stay consistent.Testing
Added regression coverage in
bindings/python/tests/tuple_tests.py:Nonestill packs/unpacks as NULL (including nested).__eq__matchingNoneraiseValueError(no silent NULL).__class__→bytes, wrapsNone) still packs as NULL.Ran locally (with a generated
apiversion.pystub for import):Also verified Value-like non-None bytes still pack identically to real
bytes, andcomparewithNonestill works.