From 296bbf0d9a34bbcf2a3d24db729da3e87e4ca285 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Tue, 19 Sep 2023 03:48:37 +0000 Subject: [PATCH] _pydantic_compat: fix HAS_PYDANTIC_V2 version check Old pydantic v1 versions do not define `__version__`. --- synapse/_pydantic_compat.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/synapse/_pydantic_compat.py b/synapse/_pydantic_compat.py index 2318fa74d427..b600c502fc5d 100644 --- a/synapse/_pydantic_compat.py +++ b/synapse/_pydantic_compat.py @@ -1,5 +1,11 @@ from packaging.version import Version -from pydantic import __version__ as pydantic_version + +try: + from pydantic import __version__ as pydantic_version +except ImportError: + import importlib.metadata + + pydantic_version = importlib.metadata.version("pydantic") HAS_PYDANTIC_V2: bool = Version(pydantic_version).major == 2