From 5307138b03a932ce95666673a80381b09394ccff Mon Sep 17 00:00:00 2001 From: Daniel Solmann <70720738+DanielSolmann@users.noreply.github.com> Date: Thu, 25 Feb 2021 13:29:04 +0300 Subject: [PATCH 1/3] Fix a typo --- docs/fastapi.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/fastapi.md b/docs/fastapi.md index 2bf7645..9efdde8 100644 --- a/docs/fastapi.md +++ b/docs/fastapi.md @@ -58,7 +58,7 @@ async def shutdown() -> None: Define ormar models with appropriate fields. -Those models will be used insted of pydantic ones. +Those models will be used instead of pydantic ones. ```python class Category(ormar.Model): @@ -210,4 +210,4 @@ def test_all_endpoints(): [fastapi]: https://fastapi.tiangolo.com/ [models]: ./models/index.md [database initialization]: ./models/migrations.md -[tests]: https://github.com/collerek/ormar/tree/master/tests \ No newline at end of file +[tests]: https://github.com/collerek/ormar/tree/master/tests From 62a6fb906325d214f7b71d4bd3bf9f47f9a49503 Mon Sep 17 00:00:00 2001 From: collerek Date: Sun, 28 Feb 2021 09:16:36 +0100 Subject: [PATCH 2/3] fix after pydantic update, pin dependencies --- docs/releases.md | 6 ++++++ ormar/__init__.py | 2 +- ormar/fields/base.py | 4 +++- ormar/models/helpers/pydantic.py | 2 +- setup.py | 8 ++++++-- tests/test_choices_schema.py | 6 +++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/releases.md b/docs/releases.md index 30e6fcb..a14b531 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -1,3 +1,9 @@ +# 0.9.5 + +## Fixes +* Fix creation of `pydantic` FieldInfo after update of `pydantic` to version >=1.8 +* Pin required dependency versions to avoid such situations in the future + # 0.9.4 ## Fixes diff --git a/ormar/__init__.py b/ormar/__init__.py index b2c7020..0768edf 100644 --- a/ormar/__init__.py +++ b/ormar/__init__.py @@ -68,7 +68,7 @@ class UndefinedType: # pragma no cover Undefined = UndefinedType() -__version__ = "0.9.4" +__version__ = "0.9.5" __all__ = [ "Integer", "BigInteger", diff --git a/ormar/fields/base.py b/ormar/fields/base.py index 08308d8..513d40a 100644 --- a/ormar/fields/base.py +++ b/ormar/fields/base.py @@ -1,3 +1,4 @@ +import inspect from typing import Any, List, Optional, TYPE_CHECKING, Type, Union import sqlalchemy @@ -89,9 +90,10 @@ class BaseField(FieldInfo): :rtype: bool """ return ( - field_name not in ["default", "default_factory", "alias"] + field_name not in ["default", "default_factory", "alias", "allow_mutation"] and not field_name.startswith("__") and hasattr(cls, field_name) + and not callable(getattr(cls, field_name)) ) @classmethod diff --git a/ormar/models/helpers/pydantic.py b/ormar/models/helpers/pydantic.py index 6a8f8a5..0ff175e 100644 --- a/ormar/models/helpers/pydantic.py +++ b/ormar/models/helpers/pydantic.py @@ -97,7 +97,7 @@ def populate_pydantic_default_values(attrs: Dict) -> Tuple[Dict, Dict]: BaseField class. Trigger conversion of ormar field into pydantic FieldInfo, which has all needed - paramaters saved. + parameters saved. Overwrites the annotations of ormar fields to corresponding types declared on ormar fields (constructed dynamically for relations). diff --git a/setup.py b/setup.py index 909a738..a37f0b8 100644 --- a/setup.py +++ b/setup.py @@ -45,15 +45,19 @@ setup( description="A simple async ORM with fastapi in mind and pydantic validation.", long_description=get_long_description(), long_description_content_type="text/markdown", - keywords=['orm', 'sqlalchemy', 'fastapi', 'pydantic', 'databases', 'async', 'alembic'], + keywords=['orm', 'sqlalchemy', 'fastapi', 'pydantic', 'databases', 'async', + 'alembic'], author="Radosław Drążkiewicz", author_email="collerek@gmail.com", packages=get_packages(PACKAGE), package_data={PACKAGE: ["py.typed"]}, include_package_data=True, zip_safe=False, + python_requires=">=3.6", data_files=[("", ["LICENSE.md"])], - install_requires=["databases", "pydantic>=1.5", "sqlalchemy", "typing_extensions"], + install_requires=["databases>=0.3.2,<=0.4.1", "pydantic>=1.6.1,<=1.8", + "sqlalchemy>=1.3.18,<=1.3.23", + "typing_extensions>=3.7,<=3.7.4.3"], extras_require={ "postgresql": ["asyncpg", "psycopg2"], "mysql": ["aiomysql", "pymysql"], diff --git a/tests/test_choices_schema.py b/tests/test_choices_schema.py index 0cf1852..978c3f6 100644 --- a/tests/test_choices_schema.py +++ b/tests/test_choices_schema.py @@ -22,7 +22,7 @@ uuid1 = uuid.uuid4() uuid2 = uuid.uuid4() -class TestEnum(Enum): +class EnumTest(Enum): val1 = "Val1" val2 = "Val2" @@ -56,7 +56,7 @@ class Organisation(ormar.Model): ) random_json: pydantic.Json = ormar.JSON(choices=["aa", '{"aa":"bb"}']) random_uuid: uuid.UUID = ormar.UUID(choices=[uuid1, uuid2]) - enum_string: str = ormar.String(max_length=100, choices=list(TestEnum)) + enum_string: str = ormar.String(max_length=100, choices=list(EnumTest)) @app.on_event("startup") @@ -110,7 +110,7 @@ def test_all_endpoints(): "random_decimal": 12.4, "random_json": '{"aa":"bb"}', "random_uuid": str(uuid1), - "enum_string": TestEnum.val1.value, + "enum_string": EnumTest.val1.value, }, ) From 86978ce809679b8ef16127729ae213285dab6c49 Mon Sep 17 00:00:00 2001 From: collerek Date: Sun, 28 Feb 2021 09:21:38 +0100 Subject: [PATCH 3/3] fix mypy --- ormar/fields/foreign_key.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ormar/fields/foreign_key.py b/ormar/fields/foreign_key.py index 35a7b2a..5e1e86c 100644 --- a/ormar/fields/foreign_key.py +++ b/ormar/fields/foreign_key.py @@ -73,7 +73,7 @@ def create_dummy_model( "".join(choices(string.ascii_uppercase, k=2)) + uuid.uuid4().hex[:4] ).lower() fields = {f"{pk_field.name}": (pk_field.__type__, None)} - dummy_model = create_model( + dummy_model = create_model( # type: ignore f"PkOnly{base_model.get_name(lower=False)}{alias}", __module__=base_model.__module__, **fields, # type: ignore