From 67d7ea226becc00b742fb4389aaa5237c567f0a9 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 2 Dec 2024 13:16:30 +0800 Subject: [PATCH] :bug: Fix pydantic basemodel v2 default config --- modules/apihelper/models/genshin/akasha.py | 3 +-- modules/gacha_log/models.py | 4 ++-- utils/patch/pydantic_basemodel.py | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 utils/patch/pydantic_basemodel.py diff --git a/modules/apihelper/models/genshin/akasha.py b/modules/apihelper/models/genshin/akasha.py index 28523e4a..3efc1f3f 100644 --- a/modules/apihelper/models/genshin/akasha.py +++ b/modules/apihelper/models/genshin/akasha.py @@ -2,8 +2,7 @@ from datetime import datetime from enum import Enum from typing import Dict, List, Any, Optional -from pydantic import Field -from simnet.models.base import APIModel as BaseModel +from pydantic import BaseModel, Field class AkashaSubStat(str, Enum): diff --git a/modules/gacha_log/models.py b/modules/gacha_log/models.py index 3e4d29e2..c1372b8d 100644 --- a/modules/gacha_log/models.py +++ b/modules/gacha_log/models.py @@ -2,9 +2,9 @@ import datetime from enum import Enum from typing import Any, Dict, List, Union, Optional -from pydantic import field_validator +from pydantic import field_validator, BaseModel -from simnet.models.base import APIModel as BaseModel, DateTimeField, add_timezone +from simnet.models.base import DateTimeField, add_timezone from metadata.shortname import not_real_roles, roleToId, weaponToId from modules.gacha_log.const import UIGF_VERSION diff --git a/utils/patch/pydantic_basemodel.py b/utils/patch/pydantic_basemodel.py new file mode 100644 index 00000000..36f35b12 --- /dev/null +++ b/utils/patch/pydantic_basemodel.py @@ -0,0 +1,5 @@ +import pydantic + +pydantic.BaseModel.model_config["extra"] = "allow" +pydantic.BaseModel.model_config["coerce_numbers_to_str"] = True +pydantic.BaseModel.model_config["arbitrary_types_allowed"] = True