Merge pull request #329 from collerek/check_pydantic_fields_order

Bug fixes
This commit is contained in:
collerek
2021-09-01 12:11:54 +02:00
committed by GitHub
5 changed files with 55 additions and 4 deletions

View File

@ -1,8 +1,15 @@
# 0.10.18
## 🐛 Fixes
* Fix order of fields in pydantic models [#328](https://github.com/collerek/ormar/issues/328)
* Fix databases 0.5.0 support [#142](https://github.com/collerek/ormar/issues/142)
# 0.10.17
## ✨ Features
* Allow overwriting the default pydantic type for model fields [#312](https://github.com/collerek/ormar/issues/285)
* Allow overwriting the default pydantic type for model fields [#312](https://github.com/collerek/ormar/issues/312)
* Add support for `sqlalchemy` >=1.4 (requires `databases` >= 0.5.0) [#142](https://github.com/collerek/ormar/issues/142)
# 0.10.16

View File

@ -77,7 +77,7 @@ class UndefinedType: # pragma no cover
Undefined = UndefinedType()
__version__ = "0.10.17"
__version__ = "0.10.18"
__all__ = [
"Integer",
"BigInteger",

View File

@ -64,6 +64,9 @@ class PydanticMixin(RelationMixin):
fields_to_process = cls._get_not_excluded_fields(
fields={*cls.Meta.model_fields.keys()}, include=include, exclude=exclude
)
fields_to_process.sort(
key=lambda x: list(cls.Meta.model_fields.keys()).index(x)
)
for name in fields_to_process:
field = cls._determine_pydantic_field_type(
name=name,

View File

@ -63,9 +63,9 @@ setup(
python_requires=">=3.6",
data_files=[("", ["LICENSE.md"])],
install_requires=[
"databases>=0.3.2,<0.4.4",
"databases>=0.3.2,<0.5.1",
"pydantic>=1.6.1,!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<=1.8.2",
"sqlalchemy>=1.3.18,<=1.3.23",
"sqlalchemy>=1.3.18,<=1.4.23",
"typing_extensions>=3.7,<=3.7.4.3",
],
extras_require={

View File

@ -0,0 +1,41 @@
import databases
import pytest
import sqlalchemy
import ormar
from tests.settings import DATABASE_URL
metadata = sqlalchemy.MetaData()
database = databases.Database(DATABASE_URL)
class BaseMeta(ormar.ModelMeta):
database = database
metadata = metadata
class TestModel(ormar.Model):
class Meta:
database = database
metadata = metadata
a: int = ormar.Integer(primary_key=True)
b: str = ormar.String(max_length=1)
c: str = ormar.String(max_length=1)
d: str = ormar.String(max_length=1)
e: str = ormar.String(max_length=1)
f: str = ormar.String(max_length=1)
@pytest.fixture(autouse=True, scope="module")
def create_test_database():
engine = sqlalchemy.create_engine(DATABASE_URL)
metadata.drop_all(engine)
metadata.create_all(engine)
yield
metadata.drop_all(engine)
def test_model_field_order():
TestCreate = TestModel.get_pydantic(exclude={"a"})
assert list(TestCreate.__fields__.keys()) == ["b", "c", "d", "e", "f"]