[Compatibility Issue] `litestar.contrib.pydantic` removed in litestar 3.0
Affected File
src/evidently/utils/schema.py:17, 55
Current Code
from litestar.contrib.pydantic import PydanticSchemaPlugin
class PolymorphicPydanticSchemaPlugin(PydanticSchemaPlugin):
"""Changes all fields with PolymorphicModel base class types into a union of it's subtypes"""
...
Root Cause
litestar.contrib.pydantic was a deprecation-warning re-export shim that forwarded to litestar.plugins.pydantic. It was deprecated since litestar 2.12 and removed in litestar 3.0.0. Any import from litestar.contrib.pydantic now raises:
ModuleNotFoundError: No module named 'litestar.contrib.pydantic'
The replacement import path is litestar.plugins.pydantic.
Impact
- Severity: High — runtime crash on litestar >= 3.0.0
Solution
# Before:
from litestar.contrib.pydantic import PydanticSchemaPlugin
# After:
try:
from litestar.plugins.pydantic import PydanticSchemaPlugin
except ImportError: # backward compatibility with older litestar
from litestar.contrib.pydantic import PydanticSchemaPlugin
References
- litestar-org/litestar#4306 — PR #4339 removed the entire deprecated
litestar.contrib.pydanticmodule
Following up with two corrections to the report above, both verified against real versions:
1. The fix is simpler than the try/except shown above. litestar.plugins.pydantic has existed and exported PydanticSchemaPlugin since litestar 2.19.0 (verified in the v2.19.0 source), and this repo's dependency floor is exactly litestar>=2.19.0 (evidently 0.7.21 METADATA, no upper bound). So the change is a plain import swap:
from litestar.plugins.pydantic import PydanticSchemaPlugin
No try/except fallback is needed: across the entire supported version range the fallback branch is unreachable, and it would mask a real ImportError if one ever fires.
2. The impact scope is smaller than stated. src/evidently/utils/schema.py has no in-repo importers (searched from evidently.utils.schema import ..., from evidently.utils import schema, import evidently.utils.schema, and PolymorphicPydanticSchemaPlugin — the only hit is the definition itself). The module ships in the wheel as public API for direct import. So litestar 3.0 does not break evidently's own runtime; the break is limited to downstream code importing this module directly. It is still worth fixing as public API surface, but it is not a runtime crash of evidently itself.
For reference: PR #1912 (koi-lee) already implements this direction via a try/except compat module — this issue can be linked to it.