| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,7 +67,7 @@ jobs: | |||
| 67 | 67 | if: matrix.pydantic-version == 'pydantic-v2' | |
| 68 | 68 | run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0" | |
| 69 | 69 | - name: Lint | |
| 70 | - if: matrix.pydantic-version == 'pydantic-v2' | ||
| 70 | + if: matrix.pydantic-version == 'pydantic-v2' && matrix.python-version != '3.8' | ||
| 71 | 71 | run: bash scripts/lint.sh | |
| 72 | 72 | - run: mkdir coverage | |
| 73 | 73 | - name: Test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,7 +103,14 @@ def set_config_value( | |||
| 103 | 103 | model.model_config[parameter] = value # type: ignore[literal-required] | |
| 104 | 104 | ||
| 105 | 105 | def get_model_fields(model: InstanceOrType[BaseModel]) -> Dict[str, "FieldInfo"]: | |
| 106 | - return model.model_fields | ||
| 106 | + # TODO: refactor the usage of this function to always pass the class | ||
| 107 | + # not the instance, and then remove this extra check | ||
| 108 | + # this is for compatibility with Pydantic v3 | ||
| 109 | + if isinstance(model, type): | ||
| 110 | + use_model = model | ||
| 111 | + else: | ||
| 112 | + use_model = model.__class__ | ||
| 113 | + return use_model.model_fields | ||
| 107 | 114 | ||
| 108 | 115 | def get_fields_set( | |
| 109 | 116 | object: InstanceOrType["SQLModel"], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -477,7 +477,7 @@ def Relationship( | |||
| 477 | 477 | class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta): | |
| 478 | 478 | __sqlmodel_relationships__: Dict[str, RelationshipInfo] | |
| 479 | 479 | model_config: SQLModelConfig | |
| 480 | - model_fields: Dict[str, FieldInfo] # type: ignore[assignment] | ||
| 480 | + model_fields: ClassVar[Dict[str, FieldInfo]] | ||
| 481 | 481 | __config__: Type[SQLModelConfig] | |
| 482 | 482 | __fields__: Dict[str, ModelField] # type: ignore[assignment] | |
| 483 | 483 | ||
@@ -839,7 +839,7 @@ def __tablename__(cls) -> str: | |||
| 839 | 839 | return cls.__name__.lower() | |
| 840 | 840 | ||
| 841 | 841 | @classmethod | |
| 842 | - def model_validate( | ||
| 842 | + def model_validate( # type: ignore[override] | ||
| 843 | 843 | cls: Type[_TSQLModel], | |
| 844 | 844 | obj: Any, | |
| 845 | 845 | *, | |
@@ -863,20 +863,25 @@ def model_dump( | |||
| 863 | 863 | mode: Union[Literal["json", "python"], str] = "python", | |
| 864 | 864 | include: Union[IncEx, None] = None, | |
| 865 | 865 | exclude: Union[IncEx, None] = None, | |
| 866 | - context: Union[Dict[str, Any], None] = None, | ||
| 867 | - by_alias: bool = False, | ||
| 866 | + context: Union[Any, None] = None, | ||
| 867 | + by_alias: Union[bool, None] = None, | ||
| 868 | 868 | exclude_unset: bool = False, | |
| 869 | 869 | exclude_defaults: bool = False, | |
| 870 | 870 | exclude_none: bool = False, | |
| 871 | 871 | round_trip: bool = False, | |
| 872 | 872 | warnings: Union[bool, Literal["none", "warn", "error"]] = True, | |
| 873 | + fallback: Union[Callable[[Any], Any], None] = None, | ||
| 873 | 874 | serialize_as_any: bool = False, | |
| 874 | 875 | ) -> Dict[str, Any]: | |
| 876 | + if PYDANTIC_MINOR_VERSION < (2, 11): | ||
| 877 | + by_alias = by_alias or False | ||
| 875 | 878 | if PYDANTIC_MINOR_VERSION >= (2, 7): | |
| 876 | 879 | extra_kwargs: Dict[str, Any] = { | |
| 877 | 880 | "context": context, | |
| 878 | 881 | "serialize_as_any": serialize_as_any, | |
| 879 | 882 | } | |
| 883 | + if PYDANTIC_MINOR_VERSION >= (2, 11): | ||
| 884 | + extra_kwargs["fallback"] = fallback | ||
| 880 | 885 | else: | |
| 881 | 886 | extra_kwargs = {} | |
| 882 | 887 | if IS_PYDANTIC_V2: | |
@@ -896,7 +901,7 @@ def model_dump( | |||
| 896 | 901 | return super().dict( | |
| 897 | 902 | include=include, | |
| 898 | 903 | exclude=exclude, | |
| 899 | - by_alias=by_alias, | ||
| 904 | + by_alias=by_alias or False, | ||
| 900 | 905 | exclude_unset=exclude_unset, | |
| 901 | 906 | exclude_defaults=exclude_defaults, | |
| 902 | 907 | exclude_none=exclude_none, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments