mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-10-29 17:19:31 +08:00
💚 Fix linting in CI (#1340)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6c0410ea91
commit
4b5ad42c23
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -67,7 +67,7 @@ jobs:
|
|||||||
if: matrix.pydantic-version == 'pydantic-v2'
|
if: matrix.pydantic-version == 'pydantic-v2'
|
||||||
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
|
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
|
||||||
- name: Lint
|
- name: Lint
|
||||||
if: matrix.pydantic-version == 'pydantic-v2'
|
if: matrix.pydantic-version == 'pydantic-v2' && matrix.python-version != '3.8'
|
||||||
run: bash scripts/lint.sh
|
run: bash scripts/lint.sh
|
||||||
- run: mkdir coverage
|
- run: mkdir coverage
|
||||||
- name: Test
|
- name: Test
|
||||||
|
|||||||
@ -103,7 +103,14 @@ if IS_PYDANTIC_V2:
|
|||||||
model.model_config[parameter] = value # type: ignore[literal-required]
|
model.model_config[parameter] = value # type: ignore[literal-required]
|
||||||
|
|
||||||
def get_model_fields(model: InstanceOrType[BaseModel]) -> Dict[str, "FieldInfo"]:
|
def get_model_fields(model: InstanceOrType[BaseModel]) -> Dict[str, "FieldInfo"]:
|
||||||
return model.model_fields
|
# TODO: refactor the usage of this function to always pass the class
|
||||||
|
# not the instance, and then remove this extra check
|
||||||
|
# this is for compatibility with Pydantic v3
|
||||||
|
if isinstance(model, type):
|
||||||
|
use_model = model
|
||||||
|
else:
|
||||||
|
use_model = model.__class__
|
||||||
|
return use_model.model_fields
|
||||||
|
|
||||||
def get_fields_set(
|
def get_fields_set(
|
||||||
object: InstanceOrType["SQLModel"],
|
object: InstanceOrType["SQLModel"],
|
||||||
|
|||||||
@ -477,7 +477,7 @@ def Relationship(
|
|||||||
class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
|
class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta):
|
||||||
__sqlmodel_relationships__: Dict[str, RelationshipInfo]
|
__sqlmodel_relationships__: Dict[str, RelationshipInfo]
|
||||||
model_config: SQLModelConfig
|
model_config: SQLModelConfig
|
||||||
model_fields: Dict[str, FieldInfo] # type: ignore[assignment]
|
model_fields: ClassVar[Dict[str, FieldInfo]]
|
||||||
__config__: Type[SQLModelConfig]
|
__config__: Type[SQLModelConfig]
|
||||||
__fields__: Dict[str, ModelField] # type: ignore[assignment]
|
__fields__: Dict[str, ModelField] # type: ignore[assignment]
|
||||||
|
|
||||||
@ -839,7 +839,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
|
|||||||
return cls.__name__.lower()
|
return cls.__name__.lower()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def model_validate(
|
def model_validate( # type: ignore[override]
|
||||||
cls: Type[_TSQLModel],
|
cls: Type[_TSQLModel],
|
||||||
obj: Any,
|
obj: Any,
|
||||||
*,
|
*,
|
||||||
@ -863,20 +863,25 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
|
|||||||
mode: Union[Literal["json", "python"], str] = "python",
|
mode: Union[Literal["json", "python"], str] = "python",
|
||||||
include: Union[IncEx, None] = None,
|
include: Union[IncEx, None] = None,
|
||||||
exclude: Union[IncEx, None] = None,
|
exclude: Union[IncEx, None] = None,
|
||||||
context: Union[Dict[str, Any], None] = None,
|
context: Union[Any, None] = None,
|
||||||
by_alias: bool = False,
|
by_alias: Union[bool, None] = None,
|
||||||
exclude_unset: bool = False,
|
exclude_unset: bool = False,
|
||||||
exclude_defaults: bool = False,
|
exclude_defaults: bool = False,
|
||||||
exclude_none: bool = False,
|
exclude_none: bool = False,
|
||||||
round_trip: bool = False,
|
round_trip: bool = False,
|
||||||
warnings: Union[bool, Literal["none", "warn", "error"]] = True,
|
warnings: Union[bool, Literal["none", "warn", "error"]] = True,
|
||||||
|
fallback: Union[Callable[[Any], Any], None] = None,
|
||||||
serialize_as_any: bool = False,
|
serialize_as_any: bool = False,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
|
if PYDANTIC_MINOR_VERSION < (2, 11):
|
||||||
|
by_alias = by_alias or False
|
||||||
if PYDANTIC_MINOR_VERSION >= (2, 7):
|
if PYDANTIC_MINOR_VERSION >= (2, 7):
|
||||||
extra_kwargs: Dict[str, Any] = {
|
extra_kwargs: Dict[str, Any] = {
|
||||||
"context": context,
|
"context": context,
|
||||||
"serialize_as_any": serialize_as_any,
|
"serialize_as_any": serialize_as_any,
|
||||||
}
|
}
|
||||||
|
if PYDANTIC_MINOR_VERSION >= (2, 11):
|
||||||
|
extra_kwargs["fallback"] = fallback
|
||||||
else:
|
else:
|
||||||
extra_kwargs = {}
|
extra_kwargs = {}
|
||||||
if IS_PYDANTIC_V2:
|
if IS_PYDANTIC_V2:
|
||||||
@ -896,7 +901,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
|
|||||||
return super().dict(
|
return super().dict(
|
||||||
include=include,
|
include=include,
|
||||||
exclude=exclude,
|
exclude=exclude,
|
||||||
by_alias=by_alias,
|
by_alias=by_alias or False,
|
||||||
exclude_unset=exclude_unset,
|
exclude_unset=exclude_unset,
|
||||||
exclude_defaults=exclude_defaults,
|
exclude_defaults=exclude_defaults,
|
||||||
exclude_none=exclude_none,
|
exclude_none=exclude_none,
|
||||||
|
|||||||
Reference in New Issue
Block a user