Skip to content

Commit

Permalink
fix: sort many args (#468)
Browse files Browse the repository at this point in the history
* fix: sort many args

* fix: test model

* version: 1.16.7
  • Loading branch information
roman-right authored Jan 3, 2023
1 parent 9d075d1 commit 06ed11b
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion beanie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from beanie.odm.views import View
from beanie.odm.union_doc import UnionDoc

__version__ = "1.16.6"
__version__ = "1.16.7"
__all__ = [
# ODM
"Document",
Expand Down
2 changes: 2 additions & 0 deletions beanie/odm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def __hash__(self):
return hash(str(self))

def __eq__(self, other):
if isinstance(other, ExpressionField):
return super(ExpressionField, self).__eq__(other)
return Eq(field=self, other=other)

def __gt__(self, other):
Expand Down
14 changes: 13 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Beanie project

## [1.16.7] - 2023-01-03

### Fix

- sort many args

### Implementation

- PR <https://github.com/roman-right/beanie/pull/468>

## [1.16.6] - 2022-12-27

### Feature
Expand Down Expand Up @@ -1214,4 +1224,6 @@ how specific type should be presented in the database

[1.15.5]: https://pypi.org/project/beanie/1.15.5

[1.16.6]: https://pypi.org/project/beanie/1.16.6
[1.16.6]: https://pypi.org/project/beanie/1.16.6

[1.16.7]: https://pypi.org/project/beanie/1.16.7
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "beanie"
version = "1.16.6"
version = "1.16.7"
description = "Asynchronous Python ODM for MongoDB"
authors = ["Roman <[email protected]>"]
license = "Apache-2.0"
Expand Down
4 changes: 4 additions & 0 deletions tests/odm/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ async def preset_documents(point):
optional=optional,
)

const = "TEST"

sample = Sample(
timestamp=timestamp,
increment=i,
Expand All @@ -116,7 +118,9 @@ async def preset_documents(point):
optional=optional,
union=union,
geo=geo,
const=const,
)

docs.append(sample)
await Sample.insert_many(documents=docs)

Expand Down
1 change: 1 addition & 0 deletions tests/odm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Sample(Document):
optional: Optional[Option2]
union: Union[Option1, Option2]
geo: GeoObject
const: str = "TEST"


class SubDocument(BaseModel):
Expand Down
12 changes: 12 additions & 0 deletions tests/odm/query/test_find.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ async def test_sort(preset_documents):
assert i_buf >= a.integer
i_buf = a.integer

result = (
await Sample.find_many(Sample.integer > 1)
.sort([Sample.const, -Sample.integer])
.to_list()
)
i_buf = None
for a in result:
if i_buf is None:
i_buf = a.integer
assert i_buf >= a.integer
i_buf = a.integer

with pytest.raises(TypeError):
Sample.find_many(Sample.integer > 1, sort=1)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_beanie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "1.16.6"
assert __version__ == "1.16.7"

0 comments on commit 06ed11b

Please sign in to comment.