fix: include class-based UDF instance state in hash - #1925
Open
ilongin wants to merge 7 commits into
Open
Conversation
Deploying datachain with
|
| Latest commit: |
08fc4ba
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5b439428.datachain-2g6.pages.dev |
| Branch Preview URL: | https://ilongin-1903-class-udf-hash.datachain-2g6.pages.dev |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ilongin
marked this pull request as draft
August 18, 2026 12:03
…om:datachain-ai/datachain into ilongin/1903-class-udf-hash-instance-state
Contributor
There was a problem hiding this comment.
Pull request overview
Updates UDF cache identities to distinguish class instances with different constructor arguments, preventing stale cached results.
Changes:
- Adds normalized value hashing for class-based UDF constructor arguments.
- Preserves deterministic Arrow/Hugging Face and LLM identities.
- Adds unit and functional regression coverage.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/datachain/hash_utils.py |
Adds normalized value hashing utilities. |
src/datachain/lib/udf.py |
Incorporates constructor arguments into UDF hashes. |
src/datachain/lib/arrow.py |
Excludes dynamic output schemas from constructor hashes. |
src/datachain/lib/hf.py |
Excludes dynamic output schemas from constructor hashes. |
src/datachain/llm/spec.py |
Reuses shared hash normalization. |
tests/func/test_udf.py |
Tests distinct aggregate results by constructor state. |
tests/unit/lib/test_arrow.py |
Tests Arrow constructor hashing. |
tests/unit/lib/test_hf.py |
Tests Hugging Face constructor hashing. |
tests/unit/lib/test_llm.py |
Removes superseded canonicalization coverage. |
tests/unit/lib/test_udf.py |
Tests UDF hash variation and determinism. |
tests/unit/test_hash_utils.py |
Tests hash-value normalization. |
tests/unit/test_query_steps_hash.py |
Updates expected query hashes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Fixes #1903.
Class-based UDFs (
Mapper/Generator/Aggregatorsubclasses) hashed to the same value regardless of constructor args, so the second.agg(CountAbove(3), ...)call was served the first.agg(CountAbove(0), ...)'s cached rows. No error, no version bump, wrong numbers.Changes:
UDFBase.hash()now mixes in_hash_state()bytes when the UDF is class-based (self._func is None). Default_hash_state()returnsfiltered_cloudpickle_dumps(self), so instance attributes likeself.limitend up in the hash.ArrowGeneratorandHFGeneratoroverride_hash_state()to skipself.output_schema, which is a dynamically-created pydantic class with a random name suffix. The schema's stable field shape is already inself.output.hash(), so no signal is lost anddc.read_csv/dc.read_parquethashes stay deterministic across calls.Function-based UDFs (plain lambdas and
deffunctions passed to.map()) are untouched - the pickle branch only runs for class-based UDFs.