Prepare 0.12.0 release (#892)
This commit is contained in:
@ -1,3 +1,20 @@
|
|||||||
|
# 0.12.0
|
||||||
|
|
||||||
|
## ✨ Breaking Changes
|
||||||
|
|
||||||
|
* `Queryset.bulk_create` will now raise `ModelListEmptyError` on empty list of models (by @ponytailer - thanks!) [#853](https://github.com/collerek/ormar/pull/853)
|
||||||
|
|
||||||
|
## ✨ Features
|
||||||
|
* `Model.upsert()` now handles a flag `__force_save__`: `bool` that allow upserting the models regardless of the fact if they have primary key set or not.
|
||||||
|
Note that setting this flag will cause two queries for each upserted model -> `get` to check if model exists and later `update/insert` accordingly. [#889](https://github.com/collerek/ormar/pull/853)
|
||||||
|
|
||||||
|
## 🐛 Fixes
|
||||||
|
|
||||||
|
* Fix for empty relations breaking `construct` method (by @Abdeldjalil-H - thanks!) [#870](https://github.com/collerek/ormar/issues/870)
|
||||||
|
* Fix save related not saving models with already set pks (including uuid) [#885](https://github.com/collerek/ormar/issues/885)
|
||||||
|
* Fix for wrong relations exclusions depending on the order of exclusions [#779](https://github.com/collerek/ormar/issues/779)
|
||||||
|
* Fix `property_fields` not being inherited properly [#774](https://github.com/collerek/ormar/issues/774)
|
||||||
|
|
||||||
# 0.11.3
|
# 0.11.3
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
|
|||||||
823
poetry.lock
generated
823
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@ name = "ormar"
|
|||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "ormar"
|
name = "ormar"
|
||||||
version = "0.11.3"
|
version = "0.12.0"
|
||||||
description = "A simple async ORM with fastapi in mind and pydantic validation."
|
description = "A simple async ORM with fastapi in mind and pydantic validation."
|
||||||
authors = ["Radosław Drążkiewicz <collerek@gmail.com>"]
|
authors = ["Radosław Drążkiewicz <collerek@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@ -0,0 +1,59 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
import databases
|
||||||
|
import pytest
|
||||||
|
import sqlalchemy
|
||||||
|
|
||||||
|
import ormar
|
||||||
|
from tests.settings import DATABASE_URL
|
||||||
|
|
||||||
|
metadata = sqlalchemy.MetaData()
|
||||||
|
database = databases.Database(DATABASE_URL)
|
||||||
|
|
||||||
|
|
||||||
|
class TableBase(ormar.Model):
|
||||||
|
class Meta(ormar.ModelMeta):
|
||||||
|
abstract = True
|
||||||
|
metadata = metadata
|
||||||
|
database = database
|
||||||
|
|
||||||
|
id: int = ormar.Integer(primary_key=True)
|
||||||
|
created_by: str = ormar.String(max_length=20, default="test")
|
||||||
|
created_at: datetime.datetime = ormar.DateTime(
|
||||||
|
timezone=True, default=datetime.datetime.now
|
||||||
|
)
|
||||||
|
last_modified_by: str = ormar.String(max_length=20, nullable=True)
|
||||||
|
last_modified_at: datetime.datetime = ormar.DateTime(timezone=True, nullable=True)
|
||||||
|
|
||||||
|
|
||||||
|
class NationBase(ormar.Model):
|
||||||
|
class Meta(ormar.ModelMeta):
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
name: str = ormar.String(max_length=50)
|
||||||
|
alpha2_code: str = ormar.String(max_length=2)
|
||||||
|
region: str = ormar.String(max_length=30)
|
||||||
|
subregion: str = ormar.String(max_length=30)
|
||||||
|
|
||||||
|
|
||||||
|
class Nation(NationBase, TableBase):
|
||||||
|
class Meta(ormar.ModelMeta):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_model_is_not_abstract_by_default():
|
||||||
|
async with database:
|
||||||
|
sweden = await Nation(
|
||||||
|
name="Sweden", alpha2_code="SE", region="Europe", subregion="Scandinavia"
|
||||||
|
).save()
|
||||||
|
assert sweden.id is not None
|
||||||
65
tests/test_queries/test_indirect_relations_to_self.py
Normal file
65
tests/test_queries/test_indirect_relations_to_self.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
import databases
|
||||||
|
import pytest
|
||||||
|
import sqlalchemy
|
||||||
|
|
||||||
|
import ormar
|
||||||
|
from tests.settings import DATABASE_URL
|
||||||
|
|
||||||
|
database = databases.Database(DATABASE_URL)
|
||||||
|
metadata = sqlalchemy.MetaData()
|
||||||
|
|
||||||
|
|
||||||
|
class Node(ormar.Model):
|
||||||
|
class Meta(ormar.ModelMeta):
|
||||||
|
tablename = "node"
|
||||||
|
database = database
|
||||||
|
metadata = metadata
|
||||||
|
|
||||||
|
id: int = ormar.Integer(primary_key=True)
|
||||||
|
name: str = ormar.String(max_length=120)
|
||||||
|
type: str = ormar.String(max_length=12, default="FLOW")
|
||||||
|
created_at: datetime = ormar.DateTime(timezone=True, default=datetime.now)
|
||||||
|
|
||||||
|
|
||||||
|
class Edge(ormar.Model):
|
||||||
|
class Meta(ormar.ModelMeta):
|
||||||
|
tablename = "edge"
|
||||||
|
database = database
|
||||||
|
metadata = metadata
|
||||||
|
|
||||||
|
id: str = ormar.String(primary_key=True, max_length=12)
|
||||||
|
src_node: Node = ormar.ForeignKey(Node, related_name="next_edges")
|
||||||
|
dst_node: Node = ormar.ForeignKey(Node, related_name="previous_edges")
|
||||||
|
order: int = ormar.Integer(default=1)
|
||||||
|
created_at: datetime = ormar.DateTime(timezone=True, default=datetime.now)
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_sort_order_on_main_model():
|
||||||
|
async with database:
|
||||||
|
node1 = await Node(name="Node 1").save()
|
||||||
|
node2 = await Node(name="Node 2").save()
|
||||||
|
node3 = await Node(name="Node 3").save()
|
||||||
|
|
||||||
|
await Edge(id="Side 1", src_node=node1, dst_node=node2).save()
|
||||||
|
await Edge(id="Side 2", src_node=node2, dst_node=node3, order=2).save()
|
||||||
|
await Edge(id="Side 3", src_node=node3, dst_node=node1, order=3).save()
|
||||||
|
|
||||||
|
active_nodes = await Node.objects.select_related(
|
||||||
|
["next_edges", "next_edges__dst_node"]
|
||||||
|
).all()
|
||||||
|
|
||||||
|
assert len(active_nodes) == 3
|
||||||
|
assert active_nodes[0].next_edges[0].id == "Side 1"
|
||||||
|
assert active_nodes[0].next_edges[0].dst_node.type == "FLOW"
|
||||||
Reference in New Issue
Block a user