Skip to content

Commit 6a32975

Browse files
authored
Fix grouping by in subqueries (#2021)
* Move uv into Makefile
1 parent 752762c commit 6a32975

File tree

8 files changed

+2467
-2440
lines changed

8 files changed

+2467
-2440
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
sudo apt-get update
6666
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
6767
- name: Run ci
68-
run: uv run make ci
68+
run: make ci
6969
- name: Test FastAPI/Blacksheep Example
7070
run: |
7171
PYTHONPATH=$DEST_FASTAPI uv run pytest $PYTEST_ARGS $DEST_FASTAPI/_tests.py

.github/workflows/gh-pages-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
python-version: "3.9"
1414
- uses: astral-sh/setup-uv@v6
1515
- name: Build docs
16-
run: uv run make docs
16+
run: make docs
1717
- name: Deploy release docs
1818
uses: peaceiris/actions-gh-pages@v3
1919
with:

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
python-version: "3.9"
1515
- uses: astral-sh/setup-uv@v6
1616
- name: Build docs
17-
run: uv run make docs
17+
run: make docs
1818
- name: Deploy latest docs
1919
uses: peaceiris/actions-gh-pages@v3
2020
with:

CHANGELOG.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ Changelog
77

88
.. rst-class:: emphasize-children
99

10-
0.26
10+
0.25
1111
====
1212

13-
0.26.0 (unreleased)
13+
0.25.2 (unreleased)
1414
-------------------
15-
Added
15+
Fixed
1616
^^^^^
17-
- Add `create()` method to reverse ForeignKey relations, enabling `parent.children.create()` syntax
17+
- Fix grouping by in subqueries (#2021)
18+
- Fix sqlite decimal filter error with `__gt` (#2019)
1819

19-
Fixed
20+
Added
2021
^^^^^
21-
- Fix sqlite decimal filter error with `__gt` (#2020)
22+
- Add `create()` method to reverse ForeignKey relations, enabling `parent.children.create()` syntax
2223

23-
0.25
24-
====
2524

2625
0.25.1
2726
------------------

Makefile

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ help:
2121
@echo " lint Auto-formats the code and check type hints"
2222

2323
up:
24-
@uv lock --upgrade
24+
uv lock --upgrade
2525

2626
deps:
27-
@uv sync --all-groups --extra asyncpg --extra accel --extra psycopg --extra asyncodbc --extra aiomysql $(options)
27+
uv sync --frozen --all-groups --extra asyncpg --extra accel --extra psycopg --extra asyncodbc --extra aiomysql $(options)
2828

2929
deps_with_asyncmy:
30-
@uv sync --all-groups --extra asyncpg --extra accel --extra psycopg --extra asyncodbc --extra asyncmy $(options)
30+
uv sync --frozen --all-groups --extra asyncpg --extra accel --extra psycopg --extra asyncodbc --extra asyncmy $(options)
3131

3232
check: build _check
3333
_check:
34-
ruff format --check $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
35-
ruff check $(checkfiles)
34+
uv run --frozen ruff format --check $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
35+
uv run --frozen ruff check $(checkfiles)
3636
#pylint -d C,W,R $(checkfiles)
3737
$(MAKE) _codeqc
3838

3939
style: deps _style
4040
_style:
41-
ruff format $(checkfiles)
42-
ruff check --fix $(checkfiles)
41+
uv run --frozen ruff format $(checkfiles)
42+
uv run --frozen ruff check --fix $(checkfiles)
4343

4444
lint: build _lint
4545
_lint:
@@ -48,30 +48,30 @@ _lint:
4848

4949
codeqc: build _codeqc
5050
_codeqc:
51-
mypy $(checkfiles)
52-
bandit -c pyproject.toml -r $(checkfiles)
53-
twine check dist/*
51+
uv run --frozen mypy $(checkfiles)
52+
uv run --frozen bandit -c pyproject.toml -r $(checkfiles)
53+
uv run --frozen twine check dist/*
5454

5555
test: deps
56-
$(py_warn) TORTOISE_TEST_DB=sqlite://:memory: pytest $(pytest_opts)
56+
$(py_warn) TORTOISE_TEST_DB=sqlite://:memory: uv run --frozen pytest $(pytest_opts)
5757

5858
test_sqlite:
59-
$(py_warn) TORTOISE_TEST_DB=sqlite://:memory: pytest --cov-report= $(pytest_opts)
59+
$(py_warn) TORTOISE_TEST_DB=sqlite://:memory: uv run --frozen pytest --cov-report= $(pytest_opts)
6060

6161
test_sqlite_regexp:
62-
$(py_warn) TORTOISE_TEST_DB=sqlite://:memory:?install_regexp_functions=True pytest --cov-report= $(pytest_opts)
62+
$(py_warn) TORTOISE_TEST_DB=sqlite://:memory:?install_regexp_functions=True uv run --frozen pytest --cov-report= $(pytest_opts)
6363

6464
test_postgres_asyncpg:
65-
python -V | grep PyPy || $(py_warn) TORTOISE_TEST_DB="asyncpg://postgres:$(TORTOISE_POSTGRES_PASS)@127.0.0.1:5432/test_\{\}" pytest $(pytest_opts) --cov-report=
65+
uv run --frozen python -V | grep PyPy || $(py_warn) TORTOISE_TEST_DB="asyncpg://postgres:$(TORTOISE_POSTGRES_PASS)@127.0.0.1:5432/test_\{\}" uv run --frozen pytest $(pytest_opts) --cov-report=
6666

6767
test_postgres_psycopg:
68-
python -V | grep PyPy || $(py_warn) TORTOISE_TEST_DB="psycopg://postgres:$(TORTOISE_POSTGRES_PASS)@127.0.0.1:5432/test_\{\}" pytest $(pytest_opts) --cov-report=
68+
uv run --frozen python -V | grep PyPy || $(py_warn) TORTOISE_TEST_DB="psycopg://postgres:$(TORTOISE_POSTGRES_PASS)@127.0.0.1:5432/test_\{\}" uv run --frozen pytest $(pytest_opts) --cov-report=
6969

7070
test_mysql_myisam:
71-
$(py_warn) TORTOISE_TEST_DB="mysql://root:$(TORTOISE_MYSQL_PASS)@127.0.0.1:3306/test_\{\}?storage_engine=MYISAM" pytest $(pytest_opts) --cov-report=
71+
$(py_warn) TORTOISE_TEST_DB="mysql://root:$(TORTOISE_MYSQL_PASS)@127.0.0.1:3306/test_\{\}?storage_engine=MYISAM" uv run --frozen pytest $(pytest_opts) --cov-report=
7272

7373
test_mysql:
74-
$(py_warn) TORTOISE_TEST_DB="mysql://root:$(TORTOISE_MYSQL_PASS)@127.0.0.1:3306/test_\{\}" pytest $(pytest_opts) --cov-report=
74+
$(py_warn) TORTOISE_TEST_DB="mysql://root:$(TORTOISE_MYSQL_PASS)@127.0.0.1:3306/test_\{\}" uv run --frozen pytest $(pytest_opts) --cov-report=
7575

7676
test_mysql_asyncmy:
7777
$(MAKE) deps_with_asyncmy
@@ -80,26 +80,26 @@ test_mysql_asyncmy:
8080
$(MAKE) deps
8181

8282
test_mssql:
83-
$(py_warn) TORTOISE_TEST_DB="mssql://sa:$(TORTOISE_MSSQL_PASS)@127.0.0.1:1433/test_\{\}?driver=$(TORTOISE_MSSQL_DRIVER)&TrustServerCertificate=YES" pytest $(pytest_opts) --cov-report=
83+
$(py_warn) TORTOISE_TEST_DB="mssql://sa:$(TORTOISE_MSSQL_PASS)@127.0.0.1:1433/test_\{\}?driver=$(TORTOISE_MSSQL_DRIVER)&TrustServerCertificate=YES" uv run --frozen pytest $(pytest_opts) --cov-report=
8484

8585
test_oracle:
86-
$(py_warn) TORTOISE_TEST_DB="oracle://SYSTEM:$(TORTOISE_ORACLE_PASS)@127.0.0.1:1521/test_\{\}?driver=$(TORTOISE_ORACLE_DRIVER)" pytest $(pytest_opts) --cov-report=
86+
$(py_warn) TORTOISE_TEST_DB="oracle://SYSTEM:$(TORTOISE_ORACLE_PASS)@127.0.0.1:1521/test_\{\}?driver=$(TORTOISE_ORACLE_DRIVER)" uv run --frozen pytest $(pytest_opts) --cov-report=
8787

8888
_testall: test_sqlite test_postgres_asyncpg test_postgres_psycopg test_mysql_myisam test_mysql test_mysql_asyncmy test_mssql
8989

90-
coverage report
90+
uv run --frozen coverage report
9191

9292
testall: deps _testall
9393

9494
ci: check _testall
9595

9696
docs: deps
9797
rm -fR ./build
98-
sphinx-build -M html docs build
98+
uv run --frozen sphinx-build -M html docs build
9999

100100
build: deps
101101
rm -fR dist/
102102
uv build
103103

104104
publish: deps _build
105-
twine upload dist/*
105+
uv run --frozen twine upload dist/*

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["sql", "mysql", "postgres", "psql", "sqlite", "aiosqlite", "asyncpg"
88
dynamic = [ "version" ]
99
requires-python = ">=3.9"
1010
dependencies = [
11-
"pypika-tortoise (>=0.6.1,<1.0.0)",
11+
"pypika-tortoise (>=0.6.3,<1.0.0)",
1212
"iso8601 (>=2.1.0,<3.0.0); python_version < '4.0'",
1313
"aiosqlite (>=0.16.0,<1.0.0)",
1414
"pytz",

tests/test_group_by.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from tests.testmodels import Author, Book, Event, Team, Tournament
22
from tortoise.contrib import test
3+
from tortoise.expressions import Subquery
34
from tortoise.functions import Avg, Count, Sum, Upper
45

56

@@ -317,3 +318,14 @@ async def test_group_by_nested_column(self):
317318
async def test_group_by_id_with_nested_filter(self):
318319
ret = await Book.filter(author__name="author1").group_by("id").values_list("id")
319320
self.assertEqual(set(ret), {(book.id,) for book in self.books1})
321+
322+
async def test_select_subquery_with_group_by(self):
323+
subquery = Subquery(
324+
Book.all().group_by("rating").order_by("-rating").limit(1).values("rating")
325+
)
326+
ret = (
327+
await Author.annotate(top_rating=subquery)
328+
.order_by("id")
329+
.values_list("name", "top_rating")
330+
)
331+
self.assertEqual(ret, [(self.a1.name, 9.0), (self.a2.name, 9.0)])

0 commit comments

Comments
 (0)