Skip to content

Commit

Permalink
Revert "fix: Disable SCIM if Pydantic version is under 2.7"
Browse files Browse the repository at this point in the history
This reverts commit 4c0b639.
  • Loading branch information
azmeuk committed Nov 22, 2024
1 parent 3027a7d commit 668a8b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
6 changes: 3 additions & 3 deletions synapse/_pydantic_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

pydantic_version = importlib.metadata.version("pydantic")

PYDANTIC_VERSION: Version = Version(pydantic_version)
HAS_PYDANTIC_V2: bool = Version(pydantic_version).major == 2

if TYPE_CHECKING or PYDANTIC_VERSION.major == 2:
if TYPE_CHECKING or HAS_PYDANTIC_V2:
from pydantic.v1 import (
BaseModel,
Extra,
Expand Down Expand Up @@ -74,7 +74,7 @@
from pydantic.typing import get_args

__all__ = (
"PYDANTIC_VERSION",
"HAS_PYDANTIC_V2",
"BaseModel",
"constr",
"conbytes",
Expand Down
55 changes: 23 additions & 32 deletions synapse/rest/scim.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from http import HTTPStatus
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, TypeVar, Union

from synapse._pydantic_compat import PYDANTIC_VERSION
from synapse.api.errors import SynapseError
from synapse.http.server import HttpServer
from synapse.http.servlet import (
Expand All @@ -45,37 +44,29 @@
from synapse.util.templates import mxc_to_http

try:
# As of version 0.2, scim2-models requires Pydantic 2.7+ but synapse only require Pydantic 1.7
# https://github.com/python-scim/scim2-models/blob/9a816731e0659622f0b6395e48d85ffa779487df/pyproject.toml#L30
# The SCIM API will be disabled if the installed Pydantic version is too old.

if (PYDANTIC_VERSION.major, PYDANTIC_VERSION.minor) < (2, 7):
HAS_SCIM2 = False

else:
from scim2_models import (
AuthenticationScheme,
Bulk,
ChangePassword,
Context,
Email,
Error,
ETag,
Filter,
ListResponse,
Meta,
Patch,
PhoneNumber,
Photo,
ResourceType,
Schema,
SearchRequest,
ServiceProviderConfig,
Sort,
User,
)

HAS_SCIM2 = True
from scim2_models import (
AuthenticationScheme,
Bulk,
ChangePassword,
Context,
Email,
Error,
ETag,
Filter,
ListResponse,
Meta,
Patch,
PhoneNumber,
Photo,
ResourceType,
Schema,
SearchRequest,
ServiceProviderConfig,
Sort,
User,
)

HAS_SCIM2 = True

except ImportError:
HAS_SCIM2 = False
Expand Down

0 comments on commit 668a8b8

Please sign in to comment.