From e7e595b80110ee981d04afa80f8ee7471d645416 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 11:26:08 +0200 Subject: [PATCH 01/14] dummy edit --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 81f0d68165..43c6f4659a 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,7 +4,7 @@ pytest >=7.0.1,<8.0.0 coverage[toml] >=6.2,<8.0 mypy ==1.4.1 ruff ==0.9.6 -# For FastAPI tests +# For FastAPI tests fastapi >=0.103.2 httpx ==0.24.1 dirty-equals ==0.9.0 From 8422f1b313fcbf6eff3761375bb088a725c601cd Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 11:29:09 +0200 Subject: [PATCH 02/14] update Ruff version in tests to follow pre-commit update --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 43c6f4659a..09ae735ed4 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -3,7 +3,7 @@ pytest >=7.0.1,<8.0.0 coverage[toml] >=6.2,<8.0 mypy ==1.4.1 -ruff ==0.9.6 +ruff ==0.11.2 # For FastAPI tests fastapi >=0.103.2 httpx ==0.24.1 From 3954be440f1de5a379f7dcc2c61fc4c6fadc2d59 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 15:19:23 +0200 Subject: [PATCH 03/14] revert dummy edit --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 09ae735ed4..18e4f72759 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,7 +4,7 @@ pytest >=7.0.1,<8.0.0 coverage[toml] >=6.2,<8.0 mypy ==1.4.1 ruff ==0.11.2 -# For FastAPI tests +# For FastAPI tests fastapi >=0.103.2 httpx ==0.24.1 dirty-equals ==0.9.0 From c17a72a06c5bef24786d73e4080ff0951a9577dc Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 15:19:56 +0200 Subject: [PATCH 04/14] add type ignores --- sqlmodel/_compat.py | 4 ++-- sqlmodel/main.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index d6b98aaca7..3e9a68971b 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -116,7 +116,7 @@ def init_pydantic_private_attrs(new_object: InstanceOrType["SQLModel"]) -> None: object.__setattr__(new_object, "__pydantic_private__", None) def get_annotations(class_dict: Dict[str, Any]) -> Dict[str, Any]: - return class_dict.get("__annotations__", {}) + return class_dict.get("__annotations__", {}) # type: ignore[no-any-return] def is_table_model_class(cls: Type[Any]) -> bool: config = getattr(cls, "model_config", {}) @@ -173,7 +173,7 @@ def is_field_noneable(field: "FieldInfo") -> bool: if not field.is_required(): if field.default is Undefined: return False - if field.annotation is None or field.annotation is NoneType: # type: ignore[comparison-overlap] + if field.annotation is None or field.annotation is NoneType: return True return False return False diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 45a41997fe..5ae17c02ec 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -477,7 +477,7 @@ def Relationship( class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta): __sqlmodel_relationships__: Dict[str, RelationshipInfo] model_config: SQLModelConfig - model_fields: Dict[str, FieldInfo] # type: ignore[assignment] + model_fields: Dict[str, FieldInfo] __config__: Type[SQLModelConfig] __fields__: Dict[str, ModelField] # type: ignore[assignment] @@ -839,7 +839,7 @@ def __tablename__(cls) -> str: return cls.__name__.lower() @classmethod - def model_validate( + def model_validate( # type: ignore[override] cls: Type[_TSQLModel], obj: Any, *, @@ -857,7 +857,7 @@ def model_validate( update=update, ) - def model_dump( + def model_dump( # type: ignore[override] self, *, mode: Union[Literal["json", "python"], str] = "python", From 9f34cc542343526e236bba5c01d55659115774cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 13:20:13 +0000 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20f?= =?UTF-8?q?ormat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlmodel/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 5ae17c02ec..8e4879b76d 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -839,7 +839,7 @@ def __tablename__(cls) -> str: return cls.__name__.lower() @classmethod - def model_validate( # type: ignore[override] + def model_validate( # type: ignore[override] cls: Type[_TSQLModel], obj: Any, *, From 27dd6c411db76870e369c7a6de44a02cf54f2a23 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 15:28:29 +0200 Subject: [PATCH 06/14] fix type ignores --- sqlmodel/_compat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 3e9a68971b..d6b98aaca7 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -116,7 +116,7 @@ def init_pydantic_private_attrs(new_object: InstanceOrType["SQLModel"]) -> None: object.__setattr__(new_object, "__pydantic_private__", None) def get_annotations(class_dict: Dict[str, Any]) -> Dict[str, Any]: - return class_dict.get("__annotations__", {}) # type: ignore[no-any-return] + return class_dict.get("__annotations__", {}) def is_table_model_class(cls: Type[Any]) -> bool: config = getattr(cls, "model_config", {}) @@ -173,7 +173,7 @@ def is_field_noneable(field: "FieldInfo") -> bool: if not field.is_required(): if field.default is Undefined: return False - if field.annotation is None or field.annotation is NoneType: + if field.annotation is None or field.annotation is NoneType: # type: ignore[comparison-overlap] return True return False return False From 7c132b6a251468d68938b602281c54d0d9c879e4 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 15:32:58 +0200 Subject: [PATCH 07/14] one more type ignore --- sqlmodel/_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index d6b98aaca7..1d258b7755 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -103,7 +103,7 @@ def set_config_value( model.model_config[parameter] = value # type: ignore[literal-required] def get_model_fields(model: InstanceOrType[BaseModel]) -> Dict[str, "FieldInfo"]: - return model.model_fields + return model.model_fields # type: ignore[arg-type] def get_fields_set( object: InstanceOrType["SQLModel"], From a91ce833310edd3fe3cea67bd8250baa5312273b Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 15:36:54 +0200 Subject: [PATCH 08/14] revert ruff bump --- requirements-tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index 18e4f72759..81f0d68165 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -3,7 +3,7 @@ pytest >=7.0.1,<8.0.0 coverage[toml] >=6.2,<8.0 mypy ==1.4.1 -ruff ==0.11.2 +ruff ==0.9.6 # For FastAPI tests fastapi >=0.103.2 httpx ==0.24.1 From c7c687c21cf1d2d21527cebb303a70a861373b35 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 17:34:18 +0200 Subject: [PATCH 09/14] adjust function signatures --- sqlmodel/_compat.py | 2 +- sqlmodel/main.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 1d258b7755..d6b98aaca7 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -103,7 +103,7 @@ def set_config_value( model.model_config[parameter] = value # type: ignore[literal-required] def get_model_fields(model: InstanceOrType[BaseModel]) -> Dict[str, "FieldInfo"]: - return model.model_fields # type: ignore[arg-type] + return model.model_fields def get_fields_set( object: InstanceOrType["SQLModel"], diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 8e4879b76d..1cc8f412af 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -839,15 +839,16 @@ def __tablename__(cls) -> str: return cls.__name__.lower() @classmethod - def model_validate( # type: ignore[override] + def model_validate( cls: Type[_TSQLModel], obj: Any, *, strict: Union[bool, None] = None, from_attributes: Union[bool, None] = None, context: Union[Dict[str, Any], None] = None, - update: Union[Dict[str, Any], None] = None, + **kwargs: Any, ) -> _TSQLModel: + update = kwargs.get("update", None) return sqlmodel_validate( cls=cls, obj=obj, @@ -857,25 +858,28 @@ def model_validate( # type: ignore[override] update=update, ) - def model_dump( # type: ignore[override] + def model_dump( self, *, mode: Union[Literal["json", "python"], str] = "python", include: Union[IncEx, None] = None, exclude: Union[IncEx, None] = None, - context: Union[Dict[str, Any], None] = None, - by_alias: bool = False, + context: Union[Any, None] = None, + by_alias: Union[bool, None] = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: Union[bool, Literal["none", "warn", "error"]] = True, + fallback: Callable[[Any], Any] | None = ..., serialize_as_any: bool = False, ) -> Dict[str, Any]: if PYDANTIC_MINOR_VERSION >= (2, 7): + assert isinstance(context, Dict) extra_kwargs: Dict[str, Any] = { "context": context, "serialize_as_any": serialize_as_any, + "fallback": fallback, } else: extra_kwargs = {} @@ -893,6 +897,7 @@ def model_dump( # type: ignore[override] **extra_kwargs, ) else: + assert by_alias is not None return super().dict( include=include, exclude=exclude, From 325d25bbabadbf0326033b9fc92be4ff3fb71df8 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 17:35:04 +0200 Subject: [PATCH 10/14] fix default --- sqlmodel/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 1cc8f412af..d39d7feb8e 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -871,7 +871,7 @@ def model_dump( exclude_none: bool = False, round_trip: bool = False, warnings: Union[bool, Literal["none", "warn", "error"]] = True, - fallback: Callable[[Any], Any] | None = ..., + fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False, ) -> Dict[str, Any]: if PYDANTIC_MINOR_VERSION >= (2, 7): From 3a6ca596b24b9462dcf66e38141edcd90766cb29 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 7 Apr 2025 17:37:57 +0200 Subject: [PATCH 11/14] fix type --- sqlmodel/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index d39d7feb8e..13fb85c2a3 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -871,7 +871,7 @@ def model_dump( exclude_none: bool = False, round_trip: bool = False, warnings: Union[bool, Literal["none", "warn", "error"]] = True, - fallback: Callable[[Any], Any] | None = None, + fallback: Union[Callable[[Any], Any], None] = None, serialize_as_any: bool = False, ) -> Dict[str, Any]: if PYDANTIC_MINOR_VERSION >= (2, 7): From d643ddfc8b4c84ba34974d338122fc075ed504f6 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Tue, 8 Apr 2025 15:08:30 +0200 Subject: [PATCH 12/14] don't run the lint test for Python 3.8 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 57dba1c286..f790f5aec3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,7 +67,7 @@ jobs: if: matrix.pydantic-version == 'pydantic-v2' run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0" - name: Lint - if: matrix.pydantic-version == 'pydantic-v2' + if: matrix.pydantic-version == 'pydantic-v2' and matrix.python-version != "3.8" run: bash scripts/lint.sh - run: mkdir coverage - name: Test From 05814aa49a34f2ff79f9e14c5efbfbc9714fc4d0 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Tue, 8 Apr 2025 15:18:49 +0200 Subject: [PATCH 13/14] remove assert --- sqlmodel/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 13fb85c2a3..ebbd72d8af 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -875,7 +875,6 @@ def model_dump( serialize_as_any: bool = False, ) -> Dict[str, Any]: if PYDANTIC_MINOR_VERSION >= (2, 7): - assert isinstance(context, Dict) extra_kwargs: Dict[str, Any] = { "context": context, "serialize_as_any": serialize_as_any, From a681e0ff574cbee22302f50bd7f881b2efd59fb3 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Tue, 8 Apr 2025 16:08:52 +0200 Subject: [PATCH 14/14] fix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f790f5aec3..ba177da7d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,7 +67,7 @@ jobs: if: matrix.pydantic-version == 'pydantic-v2' run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0" - name: Lint - if: matrix.pydantic-version == 'pydantic-v2' and matrix.python-version != "3.8" + if: matrix.pydantic-version == 'pydantic-v2' && matrix.python-version != "3.8" run: bash scripts/lint.sh - run: mkdir coverage - name: Test