You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.rst
+34-26Lines changed: 34 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,53 +7,61 @@ Changelog
7
7
8
8
.. rst-class:: emphasize-children
9
9
10
-
0.26
11
-
====
10
+
1.0
11
+
===
12
12
13
-
0.26.0 (unreleased)
14
-
-------------------
13
+
1.0.0
14
+
-----
15
15
16
16
.. warning::
17
17
18
-
This release contains **breaking changes** as part of the context-first architecture migration.
18
+
This is a **major release** with breaking changes.
19
19
Please read the :ref:`migration_guide` before upgrading.
20
20
21
21
Breaking Changes
22
22
^^^^^^^^^^^^^^^^
23
+
- **Minimum Python version raised to 3.10** (was 3.9). (#2062)
23
24
- **``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]``.
29
30
30
31
Added
31
32
^^^^^
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
- **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)
- 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)
48
52
49
53
Deprecated
50
54
^^^^^^^^^^
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).
52
56
53
57
Fixed
54
58
^^^^^
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)
Copy file name to clipboardExpand all lines: README.rst
+16-8Lines changed: 16 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,18 +20,14 @@ Tortoise ORM is an easy-to-use ``asyncio`` ORM *(Object Relational Mapper)* insp
20
20
21
21
You can find the docs at `Documentation <https://tortoise.github.io>`_
22
22
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
-
27
23
Tortoise ORM supports CPython 3.10 and later for SQLite, MySQL, PostgreSQL, Microsoft SQL Server, and Oracle.
28
24
29
25
Why was Tortoise ORM built?
30
26
---------------------------
31
27
32
28
Tortoise ORM was built to provide a lightweight, async-native Object-Relational Mapper for Python with a familiar Django-like API.
33
29
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):
Copy file name to clipboardExpand all lines: docs/getting_started.rst
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,11 @@ Getting started
6
6
7
7
Installation
8
8
===============
9
+
10
+
.. note::
11
+
12
+
Tortoise ORM requires **Python 3.10** or later.
13
+
9
14
The following table shows the available installation options for different databases (note that there are multiple options of clients for some databases):
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'``.
261
261
``related_name``
262
262
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:
Copy file name to clipboardExpand all lines: docs/schema.rst
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,30 @@ Here we create connection to SQLite database client and then we discover & initi
12
12
``generate_schema`` generates schema on empty database.
13
13
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.
14
14
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:
0 commit comments