From 895e27ddf1e42e792914e8432779c77a2dc3c533 Mon Sep 17 00:00:00 2001 From: Solomon Negusse Date: Tue, 27 Aug 2024 13:06:07 +0300 Subject: [PATCH 1/2] return error on date validation error --- app/models/pydantic/metadata.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/pydantic/metadata.py b/app/models/pydantic/metadata.py index e63af4f39..0c71b5451 100644 --- a/app/models/pydantic/metadata.py +++ b/app/models/pydantic/metadata.py @@ -2,6 +2,7 @@ from typing import Any, List, Optional, Union from uuid import UUID +from fastapi import HTTPException from pydantic import Field, validator, BaseModel from pydantic.utils import GetterDict @@ -182,4 +183,6 @@ def _date_validator(date_str): try: return datetime.strptime(date_str, "%Y-%m-%d").date() except (ValueError, TypeError): - return None + raise HTTPException( + status_code=422, detail="Date needs to be of the format YYYY-MM-DD" + ) From 0064218a61387931a8961258573d88b8c16911ec Mon Sep 17 00:00:00 2001 From: Solomon Negusse Date: Tue, 27 Aug 2024 19:54:15 +0300 Subject: [PATCH 2/2] pass through None in validation --- app/models/pydantic/metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/pydantic/metadata.py b/app/models/pydantic/metadata.py index 0c71b5451..f17d44b6d 100644 --- a/app/models/pydantic/metadata.py +++ b/app/models/pydantic/metadata.py @@ -177,7 +177,7 @@ class VersionMetadataWithParentResponse(Response): def _date_validator(date_str): - if isinstance(date_str, date): + if isinstance(date_str, date) or date_str is None: return date_str try: