Skip to content

fix: fix entropy patch for newer pydantic versions#153

Open
ryanking13 wants to merge 1 commit into
gyeongjae/experimental-python314from
gyeongjae/pydantic-entropy
Open

fix: fix entropy patch for newer pydantic versions#153
ryanking13 wants to merge 1 commit into
gyeongjae/experimental-python314from
gyeongjae/pydantic-entropy

Conversation

@ryanking13

Copy link
Copy Markdown
Contributor

This is on top of #129. It fixes pydantic-core entropy patch so that we can use fastapi in python 3.14

@ask-bonk

ask-bonk Bot commented Jul 9, 2026

Copy link
Copy Markdown

I've reviewed the changes carefully. Let me analyze:

Changes in _workers_sdk_entropy_import_context.py:

  1. The pydantic_core_context function now checks if validate_core_schema exists on the module via getattr.
  2. If it doesn't exist (pydantic-core >=2.41), it falls back to module.SchemaValidator({"type": "any"}) to trigger the lazy hash-map seed initialization.
  3. If it does exist (older pydantic-core), it uses the original validate_core_schema(None) approach.

Changes in worker.py (test file):

Removes the early-return guard that skipped entropy patch tests on Python 3.14, since the fix should now make them pass.

Review assessment:

The logic is sound:

  • The version detection via getattr with a fallback is the right pattern — it's duck-typing rather than fragile version comparisons.
  • SchemaValidator({"type": "any"}) is a reasonable minimal invocation to trigger the internal ahash seed initialization path.
  • The allow_bad_entropy_calls(1) wrapping is consistent with how it's used in the existing code path.
  • Removing the Python 3.14 skip in the test is the correct follow-up since the fix should make those tests pass again.
  • The code is clean and well-commented.

I don't see any logic bugs, security issues, backward compatibility problems, or other actionable issues.

LGTM

github run

Comment on lines +97 to +98
# pydantic-core >=2.41 no longer exports validate_core_schema. Build a
# tiny validator instead so any lazy hash-map seeds are initialized

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.

Suggested change
# pydantic-core >=2.41 no longer exports validate_core_schema. Build a
# tiny validator instead so any lazy hash-map seeds are initialized
# Build a tiny validator instead so any lazy hash-map seeds are initialized

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.

Can we just delete the other branch? This should work always.

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