Skip to content

Commit 1f70faa

Browse files
authored
1.0 Release updates (tortoise#2087)
* 1.0 Release updates * Remove obsolete funding * Update readme
1 parent 62db048 commit 1f70faa

File tree

12 files changed

+108
-39
lines changed

12 files changed

+108
-39
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.rst

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,61 @@ Changelog
77

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

10-
0.26
11-
====
10+
1.0
11+
===
1212

13-
0.26.0 (unreleased)
14-
-------------------
13+
1.0.0
14+
-----
1515

1616
.. warning::
1717

18-
This release contains **breaking changes** as part of the context-first architecture migration.
18+
This is a **major release** with breaking changes.
1919
Please read the :ref:`migration_guide` before upgrading.
2020

2121
Breaking Changes
2222
^^^^^^^^^^^^^^^^
23+
- **Minimum Python version raised to 3.10** (was 3.9). (#2062)
2324
- **``use_tz`` now defaults to ``True``** (was ``False``). Set ``use_tz=False`` explicitly if you need naive datetimes.
24-
- **Context-first architecture**: All ORM state now lives in ``TortoiseContext`` instances
25-
- **Removed** legacy test classes: ``test.TestCase``, ``test.IsolatedTestCase``, ``test.TruncationTestCase``, ``test.SimpleTestCase``
26-
- **Removed** legacy test helpers: ``initializer()``, ``finalizer()``, ``env_initializer()``, ``getDBConfig()``
27-
- **Changed** ``Tortoise.init()`` now returns ``TortoiseContext`` (previously returned ``None``)
28-
- **Changed** Multiple separate ``asyncio.run()`` calls in sequence require explicit context management due to ContextVar scoping (uncommon pattern, see migration guide). The typical single ``asyncio.run(main())`` pattern continues to work unchanged.
25+
- **Context-first architecture**: All ORM state now lives in ``TortoiseContext`` instances. ``Tortoise.init()`` returns a ``TortoiseContext`` (previously returned ``None``). Multiple separate ``asyncio.run()`` calls require explicit context management; the typical single ``asyncio.run(main())`` pattern works unchanged.
26+
- **Removed legacy test infrastructure**: ``test.TestCase``, ``test.IsolatedTestCase``, ``test.TruncationTestCase``, ``test.SimpleTestCase``, ``initializer()``, ``finalizer()``, ``env_initializer()``, ``getDBConfig()``. Use ``tortoise_test_context()`` with pytest instead.
27+
- **Removed ``pytz`` dependency**: Timezone handling now uses the standard library ``zoneinfo`` module. Tortoise APIs return ``ZoneInfo`` objects instead of ``pytz`` timezones. (#2023)
28+
- **``DatetimeField``/``TimeField`` with ``auto_now=True``** no longer implicitly sets ``auto_now_add=True``. In practice ``auto_now=True`` alone still sets the value on every save (including creation), so this is unlikely to affect most users. The internal flag coupling was removed for correctness.
29+
- **Shell extras required**: Interactive shell dependencies are now optional. Install with ``pip install tortoise-orm[ipython]`` or ``pip install tortoise-orm[ptpython]``.
2930

3031
Added
3132
^^^^^
32-
- ``TortoiseContext`` - explicit context manager for ORM state
33-
- ``tortoise_test_context()`` - modern pytest fixture helper for test isolation
34-
- ``get_connection(alias)`` - function to get connection by alias from current context
35-
- ``get_connections()`` - function to get the ConnectionHandler from current context
36-
- ``Tortoise.close_connections()`` - class method to close all connections
37-
- ``Tortoise.is_inited()`` - explicit method version of ``Tortoise._inited`` property
33+
- **Native migrations framework** with CLI commands: ``tortoise makemigrations``, ``tortoise migrate``, ``tortoise sqlmigrate``. Supports ``RunPython``, ``RunSQL``, reversible migrations, and multi-app projects. (#2061)
34+
- **Database schema support** for PostgreSQL and MSSQL (on MySQL maps to database name) — tables can live in non-default schemas (e.g., ``warehouse.inventory``), with cross-schema relations and migration support. (#2084)
35+
- **PostgreSQL full-text search**: ``TSVectorField``, ``SearchVector``, ``SearchQuery``, ``SearchRank``, ``SearchHeadline`` expressions, and GIN/GiST index support. (#2065)
36+
- **Query API** (``tortoise.query_api``) for building and executing custom pypika queries against models, with ``Model.get_table()`` classmethod. (#2064)
37+
- ``TortoiseContext`` — explicit context manager for ORM state with full isolation. (#2069)
38+
- ``tortoise_test_context()`` — modern pytest fixture helper for test isolation. (#2069)
39+
- ``get_connection(alias)`` / ``get_connections()`` — functions to access connections from current context.
40+
- ``Tortoise.close_connections()`` — restored (was deprecated in 0.19) as the canonical way to close connections, now context-aware.
41+
- ``Tortoise.is_inited()`` — explicit method version of ``Tortoise._inited`` property.
42+
- ``ForeignKeyField`` and ``ManyToManyField`` now accept a model class directly, not just string references. (#2027)
43+
- ``DateField`` now supports ``__year`` / ``__month`` / ``__day`` filters. (#2067)
3844

3945
Changed
4046
^^^^^^^
41-
- Framework integrations (FastAPI, Starlette, Sanic, etc.) now use ``Tortoise.close_connections()`` internally
42-
- ``ConnectionHandler`` now uses instance-based ContextVar storage (each context has isolated connections)
43-
- ``Tortoise.apps`` and ``Tortoise._inited`` now use ``classproperty`` descriptor (no metaclass)
44-
- **Shell command now uses optional dependencies**: Install with ``pip install tortoise-orm[ipython]`` (recommended) or ``pip install tortoise-orm[ptpython]`` to enable. IPython is preferred over ptpython. Both shells are supported.
45-
- **DatetimeField and TimeField behavior change**: Fields with ``auto_now=True`` no longer incorrectly set ``auto_now_add=True`` internally.
46-
- feat: foreignkey to model type (#2027)
47-
- refactor: remove `pytz` and use standard library `zoneinfo` (#2023)
47+
- Framework integrations (FastAPI, Starlette, Sanic, etc.) now use ``Tortoise.close_connections()`` internally.
48+
- ``ConnectionHandler`` uses per-instance ContextVar storage for context isolation.
49+
- ``Tortoise.apps`` and ``Tortoise._inited`` are now ``classproperty`` descriptors.
50+
- Performance optimizations for model hydration, object construction, and query building. (#2078)
51+
- Pydantic model creator internals cleaned up: removed legacy validator, improved computed field handling. (#2079)
4852

4953
Deprecated
5054
^^^^^^^^^^
51-
- ``from tortoise import connections`` - use ``get_connection()`` / ``get_connections()`` functions instead (still works but deprecated)
55+
- ``from tortoise import connections`` use ``get_connection()`` / ``get_connections()`` instead (still works but deprecated).
5256

5357
Fixed
5458
^^^^^
55-
- ``use_tz=False`` now correctly preserves naive datetimes instead of silently making them timezone-aware (#631)
56-
- Fix annotations being selected in ValuesListQuery despite not specified in `.values_list` fields list (#2059)
59+
- ``use_tz=False`` now correctly preserves naive datetimes instead of silently making them timezone-aware. (#631)
60+
- Annotations incorrectly selected in ``ValuesListQuery`` when not specified in ``.values_list()`` fields. (#2059)
61+
- M2M filtering broken when two relations point to the same target model. (#2083)
62+
- Pydantic incorrectly marking fields with default values as ``Optional``. (#2082)
63+
- ``Model.in_bulk`` type annotation now supports any primary key type. (#2075)
64+
- Migration bug fixes: field serialization, operation ordering, and ``sqlmigrate`` command added. (#2076)
5765

5866
0.25
5967
====

README.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@ Tortoise ORM is an easy-to-use ``asyncio`` ORM *(Object Relational Mapper)* insp
2020

2121
You can find the docs at `Documentation <https://tortoise.github.io>`_
2222

23-
.. note::
24-
Tortoise ORM is a young project and breaking changes are to be expected.
25-
We keep a `Changelog <https://tortoise.github.io/CHANGELOG.html>`_ and it will have possible breakage clearly documented.
26-
2723
Tortoise ORM supports CPython 3.10 and later for SQLite, MySQL, PostgreSQL, Microsoft SQL Server, and Oracle.
2824

2925
Why was Tortoise ORM built?
3026
---------------------------
3127

3228
Tortoise ORM was built to provide a lightweight, async-native Object-Relational Mapper for Python with a familiar Django-like API.
3329

34-
Tortoise ORM performs well when compared to other Python ORMs. In `our benchmarks <https://github.com/tortoise/orm-benchmarks>`_, where we measure different read and write operations (rows/sec, more is better), it's trading places with Pony ORM:
30+
Tortoise ORM performs well when compared to other Python ORMs. Here are `our benchmarks <https://github.com/tortoise/orm-benchmarks>`_ on PostgreSQL 17, where we measure different read and write operations (rows/sec, more is better):
3531

3632
.. image:: https://raw.githubusercontent.com/tortoise/tortoise-orm/develop/docs/ORM_Perf.png
3733
:target: https://github.com/tortoise/orm-benchmarks
@@ -191,9 +187,21 @@ Learn more at the `documentation site <https://tortoise.github.io>`_
191187
Migrations
192188
==========
193189

194-
Tortoise ORM ships with built-in migrations and a CLI. See the
195-
`migrations documentation <https://tortoise.github.io/migration.html>`_ for
196-
setup, commands, and examples.
190+
Tortoise ORM ships with a built-in migration framework and CLI.
191+
Autodetect model changes, generate migration files, and apply them:
192+
193+
.. code-block:: shell
194+
195+
tortoise init # create migration packages
196+
tortoise makemigrations # detect changes and generate migrations
197+
tortoise migrate # apply pending migrations
198+
tortoise sqlmigrate app 001 # preview SQL without executing
199+
200+
Migrations support ``RunPython`` and ``RunSQL`` for data migrations, offline migration generation,
201+
reversible operations, and multi-app and multi db-schema projects.
202+
203+
See the `migrations documentation <https://tortoise.github.io/migration.html>`_ for
204+
full setup and examples.
197205

198206
Contributing
199207
============

docs/ORM_Perf.png

37 KB
Loading

docs/cli.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ List migration heads on disk.
104104
tortoise heads
105105
tortoise heads users
106106
107+
sqlmigrate
108+
----------
109+
110+
Print the SQL statements for a specific migration without executing them.
111+
112+
.. code-block:: shell
113+
114+
tortoise sqlmigrate users 0001_initial
115+
tortoise sqlmigrate users 0001_initial --backward
116+
107117
shell
108118
-----
109119

docs/direct_queries.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ If your application has multiple database connections configured, you must pass
4242

4343
.. code-block:: python3
4444
45-
from tortoise.connection import connections
45+
from tortoise.connection import get_connection
4646
47-
db = connections.get("analytics")
47+
db = get_connection("analytics")
4848
result = await execute_pypika(query, using_db=db)
4949
5050
Rows Affected Semantics

docs/getting_started.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Getting started
66

77
Installation
88
===============
9+
10+
.. note::
11+
12+
Tortoise ORM requires **Python 3.10** or later.
13+
914
The following table shows the available installation options for different databases (note that there are multiple options of clients for some databases):
1015

1116
.. list-table:: Available Installation Options

docs/migration.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ List migration heads on disk.
112112
113113
tortoise heads
114114
115+
sqlmigrate
116+
----------
117+
118+
Print the SQL for a migration without executing it.
119+
120+
.. code-block:: shell
121+
122+
tortoise sqlmigrate models 0001_initial
123+
tortoise sqlmigrate models 0001_initial --backward
124+
115125
Migration files
116126
===============
117127

docs/models.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ The ``Meta`` class
257257
In event model we got some more fields, that could be interesting for us.
258258

259259
``fields.ForeignKeyField('models.Tournament', related_name='events')``
260-
Here we create foreign key reference to tournament. We create it by referring to model by it's literal, consisting of app name and model name. ``models`` is default app name, but you can change it in ``class Meta`` with ``app = 'other'``.
260+
Here we create foreign key reference to tournament. You can refer to the model either by string literal (``"app_name.ModelName"``) or by passing the model class directly (e.g. ``fields.ForeignKeyField(Tournament)``). String references are required for forward references where the target model is not yet defined. ``models`` is default app name, but you can change it in ``class Meta`` with ``app = 'other'``.
261261
``related_name``
262262
Is keyword argument, that defines field for related query on referenced models, so with that you could fetch all tournaments's events with like this:
263263

docs/schema.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ Here we create connection to SQLite database client and then we discover & initi
1212
``generate_schema`` generates schema on empty database.
1313
There is also the default option when generating the schemas to set the ``safe`` parameter to ``True`` which will only insert the tables if they don't already exist.
1414

15+
Non-default Database Schemas
16+
============================
17+
18+
Tortoise ORM supports placing tables in non-default database schemas on PostgreSQL and MSSQL
19+
(on MySQL, ``schema`` maps to a separate database name via `` `db`.`table` `` syntax).
20+
Set the ``schema`` attribute in a model's ``Meta`` class:
21+
22+
.. code-block:: python3
23+
24+
class Product(Model):
25+
name = fields.CharField(max_length=200)
26+
27+
class Meta:
28+
schema = "catalog"
29+
30+
class Inventory(Model):
31+
product = fields.ForeignKeyField("models.Product")
32+
quantity = fields.IntField()
33+
34+
class Meta:
35+
schema = "warehouse"
36+
37+
Cross-schema foreign keys work automatically. The migration framework also handles schema-qualified
38+
tables, including schema creation when needed.
1539

1640
Helper Functions
1741
================

0 commit comments

Comments
 (0)