| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0c7def8 commit 1b7b3aa
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,10 +62,10 @@ jobs: | |||
| 62 | 62 | run: python -m poetry install | |
| 63 | 63 | - name: Install Pydantic v1 | |
| 64 | 64 | if: matrix.pydantic-version == 'pydantic-v1' | |
| 65 | - run: pip install "pydantic>=1.10.0,<2.0.0" | ||
| 65 | + run: pip install --upgrade "pydantic>=1.10.0,<2.0.0" | ||
| 66 | 66 | - name: Install Pydantic v2 | |
| 67 | 67 | if: matrix.pydantic-version == 'pydantic-v2' | |
| 68 | - run: pip install "pydantic>=2.0.2,<3.0.0" | ||
| 68 | + run: pip install --upgrade "pydantic>=2.0.2,<3.0.0" | ||
| 69 | 69 | - name: Lint | |
| 70 | 70 | # Do not run on Python 3.7 as mypy behaves differently | |
| 71 | 71 | if: matrix.python-version != '3.7' && matrix.pydantic-version == 'pydantic-v2' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,10 +97,10 @@ def set_config_value( | |||
| 97 | 97 | def get_model_fields(model: InstanceOrType["SQLModel"]) -> Dict[str, "FieldInfo"]: | |
| 98 | 98 | return model.model_fields | |
| 99 | 99 | ||
| 100 | - def set_fields_set( | ||
| 101 | - new_object: InstanceOrType["SQLModel"], fields: Set["FieldInfo"] | ||
| 102 | - ) -> None: | ||
| 103 | - object.__setattr__(new_object, "__pydantic_fields_set__", fields) | ||
| 100 | + def init_pydantic_private_attrs(new_object: InstanceOrType["SQLModel"]) -> None: | ||
| 101 | + object.__setattr__(new_object, "__pydantic_fields_set__", set()) | ||
| 102 | + object.__setattr__(new_object, "__pydantic_extra__", None) | ||
| 103 | + object.__setattr__(new_object, "__pydantic_private__", None) | ||
| 104 | 104 | ||
| 105 | 105 | def get_annotations(class_dict: Dict[str, Any]) -> Dict[str, Any]: | |
| 106 | 106 | return class_dict.get("__annotations__", {}) | |
@@ -387,10 +387,8 @@ def set_config_value( | |||
| 387 | 387 | def get_model_fields(model: InstanceOrType["SQLModel"]) -> Dict[str, "FieldInfo"]: | |
| 388 | 388 | return model.__fields__ # type: ignore | |
| 389 | 389 | ||
| 390 | - def set_fields_set( | ||
| 391 | - new_object: InstanceOrType["SQLModel"], fields: Set["FieldInfo"] | ||
| 392 | - ) -> None: | ||
| 393 | - object.__setattr__(new_object, "__fields_set__", fields) | ||
| 390 | + def init_pydantic_private_attrs(new_object: InstanceOrType["SQLModel"]) -> None: | ||
| 391 | + object.__setattr__(new_object, "__fields_set__", set()) | ||
| 394 | 392 | ||
| 395 | 393 | def get_annotations(class_dict: Dict[str, Any]) -> Dict[str, Any]: | |
| 396 | 394 | return resolve_annotations( # type: ignore[no-any-return] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,11 +70,11 @@ | |||
| 70 | 70 | get_model_fields, | |
| 71 | 71 | get_relationship_to, | |
| 72 | 72 | get_type_from_field, | |
| 73 | + init_pydantic_private_attrs, | ||
| 73 | 74 | is_field_noneable, | |
| 74 | 75 | is_table_model_class, | |
| 75 | 76 | post_init_field_info, | |
| 76 | 77 | set_config_value, | |
| 77 | - set_fields_set, | ||
| 78 | 78 | sqlmodel_init, | |
| 79 | 79 | sqlmodel_validate, | |
| 80 | 80 | ) | |
@@ -686,12 +686,12 @@ class Config: | |||
| 686 | 686 | ||
| 687 | 687 | def __new__(cls, *args: Any, **kwargs: Any) -> Any: | |
| 688 | 688 | new_object = super().__new__(cls) | |
| 689 | - # SQLAlchemy doesn't call __init__ on the base class | ||
| 689 | + # SQLAlchemy doesn't call __init__ on the base class when querying from DB | ||
| 690 | 690 | # Ref: https://docs.sqlalchemy.org/en/14/orm/constructors.html | |
| 691 | 691 | # Set __fields_set__ here, that would have been set when calling __init__ | |
| 692 | 692 | # in the Pydantic model so that when SQLAlchemy sets attributes that are | |
| 693 | 693 | # added (e.g. when querying from DB) to the __fields_set__, this already exists | |
| 694 | - set_fields_set(new_object, set()) | ||
| 694 | + init_pydantic_private_attrs(new_object) | ||
| 695 | 695 | return new_object | |
| 696 | 696 | ||
| 697 | 697 | def __init__(__pydantic_self__, **data: Any) -> None: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments