Skip to content

Commit

Permalink
UrlCodec -> AnyUrlCodec (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuba authored Dec 3, 2024
1 parent b0590a7 commit f29a39c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions api/api/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
AsyncIOMotorDatabase,
AsyncIOMotorCursor,
)
import os
from enum import Enum
import bia_shared_datamodels.bia_data_model as shared_data_models
import pymongo
Expand All @@ -21,7 +20,7 @@
from bson.codec_options import TypeCodec, TypeRegistry
from bson.binary import UuidRepresentation

from pydantic_core import Url
from pydantic import AnyUrl
from api.api_logging import log_error


Expand All @@ -40,11 +39,11 @@ def transform_bson(self, value: DatetimeMS) -> datetime.date:
return value.as_datetime().date()


class UrlCodec(TypeCodec):
python_type = Url
class AnyUrlCodec(TypeCodec):
python_type = AnyUrl
bson_type = str

def transform_python(self, value: Url) -> str:
def transform_python(self, value: AnyUrl) -> str:
return str(value)

def transform_bson(self, value: str) -> str:
Expand Down Expand Up @@ -89,7 +88,7 @@ def configure(self, settings: Settings):
# Looks like explicitly setting codec_options excludes settings from the client
# so uuid_representation needs to be defined even if already defined in connection
codec_options=CodecOptions(
type_registry=TypeRegistry([DateCodec(), UrlCodec()]),
type_registry=TypeRegistry([DateCodec(), AnyUrlCodec()]),
uuid_representation=UuidRepresentation.STANDARD,
),
)
Expand Down

0 comments on commit f29a39c

Please sign in to comment.