Skip to content

Commit

Permalink
Merge pull request #329 from collerek/check_pydantic_fields_order
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
collerek authored Sep 1, 2021
2 parents 47f2d61 + 46500eb commit bccc47f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
9 changes: 8 additions & 1 deletion docs/releases.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ormar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __repr__(self) -> str:

Undefined = UndefinedType()

__version__ = "0.10.17"
__version__ = "0.10.18"
__all__ = [
"Integer",
"BigInteger",
Expand Down
3 changes: 3 additions & 0 deletions ormar/models/mixins/pydantic_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def _convert_ormar_to_pydantic(
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,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def get_packages(package):
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={
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit bccc47f

Please sign in to comment.