catch wrong uuid convertion
This commit is contained in:
parent
da00232fe7
commit
86a18ed76d
|
|
@ -1,3 +1,5 @@
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
@ -24,6 +26,10 @@ class ChainRepository:
|
||||||
return TypeAdapter(List[Chain]).validate_python(chains)
|
return TypeAdapter(List[Chain]).validate_python(chains)
|
||||||
|
|
||||||
async def get_by_id(self, chain_id: str) -> Chain | None:
|
async def get_by_id(self, chain_id: str) -> Chain | None:
|
||||||
query = {"_id": UUID(chain_id)}
|
try:
|
||||||
chain = await self.collection.find_one(query)
|
query = {"_id": UUID(chain_id)}
|
||||||
return Chain.model_validate(chain) if chain else None
|
chain = await self.collection.find_one(query)
|
||||||
|
return Chain.model_validate(chain) if chain else None
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
logger.error(f"Cannot convert {chain_id} to UUID")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user