Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
- name: Run ci
run: uv run make ci
run: make ci
- name: Test FastAPI/Blacksheep Example
run: |
PYTHONPATH=$DEST_FASTAPI uv run pytest $PYTEST_ARGS $DEST_FASTAPI/_tests.py
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
python-version: "3.9"
- uses: astral-sh/setup-uv@v6
- name: Build docs
run: uv run make docs
run: make docs
- name: Deploy release docs
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
python-version: "3.9"
- uses: astral-sh/setup-uv@v6
- name: Build docs
run: uv run make docs
run: make docs
- name: Deploy latest docs
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
15 changes: 7 additions & 8 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ Changelog

.. rst-class:: emphasize-children

0.26
0.25
====

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

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

0.25
====

0.25.1
------------------
Expand Down
44 changes: 22 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ help:
@echo " lint Auto-formats the code and check type hints"

up:
@uv lock --upgrade
uv lock --upgrade

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

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

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

style: deps _style
_style:
ruff format $(checkfiles)
ruff check --fix $(checkfiles)
uv run --frozen ruff format $(checkfiles)
uv run --frozen ruff check --fix $(checkfiles)

lint: build _lint
_lint:
Expand All @@ -48,30 +48,30 @@ _lint:

codeqc: build _codeqc
_codeqc:
mypy $(checkfiles)
bandit -c pyproject.toml -r $(checkfiles)
twine check dist/*
uv run --frozen mypy $(checkfiles)
uv run --frozen bandit -c pyproject.toml -r $(checkfiles)
uv run --frozen twine check dist/*

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

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

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

test_postgres_asyncpg:
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=
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=

test_postgres_psycopg:
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=
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=

test_mysql_myisam:
$(py_warn) TORTOISE_TEST_DB="mysql://root:$(TORTOISE_MYSQL_PASS)@127.0.0.1:3306/test_\{\}?storage_engine=MYISAM" pytest $(pytest_opts) --cov-report=
$(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=

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

test_mysql_asyncmy:
$(MAKE) deps_with_asyncmy
Expand All @@ -80,26 +80,26 @@ test_mysql_asyncmy:
$(MAKE) deps

test_mssql:
$(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=
$(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=

test_oracle:
$(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=
$(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=

_testall: test_sqlite test_postgres_asyncpg test_postgres_psycopg test_mysql_myisam test_mysql test_mysql_asyncmy test_mssql

coverage report
uv run --frozen coverage report

testall: deps _testall

ci: check _testall

docs: deps
rm -fR ./build
sphinx-build -M html docs build
uv run --frozen sphinx-build -M html docs build

build: deps
rm -fR dist/
uv build

publish: deps _build
twine upload dist/*
uv run --frozen twine upload dist/*
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["sql", "mysql", "postgres", "psql", "sqlite", "aiosqlite", "asyncpg"
dynamic = [ "version" ]
requires-python = ">=3.9"
dependencies = [
"pypika-tortoise (>=0.6.1,<1.0.0)",
"pypika-tortoise (>=0.6.3,<1.0.0)",
"iso8601 (>=2.1.0,<3.0.0); python_version < '4.0'",
"aiosqlite (>=0.16.0,<1.0.0)",
"pytz",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_group_by.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from tests.testmodels import Author, Book, Event, Team, Tournament
from tortoise.contrib import test
from tortoise.expressions import Subquery
from tortoise.functions import Avg, Count, Sum, Upper


Expand Down Expand Up @@ -317,3 +318,14 @@ async def test_group_by_nested_column(self):
async def test_group_by_id_with_nested_filter(self):
ret = await Book.filter(author__name="author1").group_by("id").values_list("id")
self.assertEqual(set(ret), {(book.id,) for book in self.books1})

async def test_select_subquery_with_group_by(self):
subquery = Subquery(
Book.all().group_by("rating").order_by("-rating").limit(1).values("rating")
)
ret = (
await Author.annotate(top_rating=subquery)
.order_by("id")
.values_list("name", "top_rating")
)
self.assertEqual(ret, [(self.a1.name, 9.0), (self.a2.name, 9.0)])
Loading