Skip to content

Commit 031d2a4

Browse files
committed
Merge polymorphic models support from upstream PR fastapi#1226
2 parents c1dff79 + 6c0410e commit 031d2a4

31 files changed

+115
-92
lines changed

‎.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
3535
run: python -m build
3636
- name: Publish
37-
uses: pypa/gh-action-pypi-publish@v1.12.3
37+
uses: pypa/gh-action-pypi-publish@v1.12.4

‎.github/workflows/test.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ jobs:
3232
- "3.10"
3333
- "3.11"
3434
- "3.12"
35+
- "3.13"
3536
pydantic-version:
3637
- pydantic-v1
3738
- pydantic-v2
38-
include:
39-
- os: ubuntu-22.04
40-
python-version: "3.7"
41-
pydantic-version: pydantic-v1
42-
- os: ubuntu-22.04
43-
python-version: "3.7"
44-
pydantic-version: pydantic-v2
4539
fail-fast: false
4640
runs-on: ${{ matrix.os }}
4741
steps:
@@ -71,10 +65,9 @@ jobs:
7165
run: uv pip install --upgrade "pydantic>=1.10.0,<2.0.0"
7266
- name: Install Pydantic v2
7367
if: matrix.pydantic-version == 'pydantic-v2'
74-
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0" "typing-extensions==4.6.1"
68+
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
7569
- name: Lint
76-
# Do not run on Python 3.7 as mypy behaves differently
77-
if: matrix.python-version != '3.7' && matrix.pydantic-version == 'pydantic-v2'
70+
if: matrix.pydantic-version == 'pydantic-v2'
7871
run: bash scripts/lint.sh
7972
- run: mkdir coverage
8073
- name: Test
@@ -97,7 +90,7 @@ jobs:
9790
- uses: actions/checkout@v4
9891
- uses: actions/setup-python@v5
9992
with:
100-
python-version: '3.12'
93+
python-version: '3.13'
10194
- name: Setup uv
10295
uses: astral-sh/setup-uv@v5
10396
with:

‎.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default_language_version:
44
python: python3.10
55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.6.0
7+
rev: v5.0.0
88
hooks:
99
- id: check-added-large-files
1010
- id: check-toml
@@ -14,7 +14,7 @@ repos:
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.6.5
17+
rev: v0.11.2
1818
hooks:
1919
- id: ruff
2020
args:

‎README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<em>SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.</em>
77
</p>
88
<p align="center">
9-
<a href="https://github.com/fastapi/sqlmodel/actions?query=workflow%3ATest" target="_blank">
10-
<img src="https://github.com/fastapi/sqlmodel/workflows/Test/badge.svg" alt="Test">
9+
<a href="https://github.com/fastapi/sqlmodel/actions?query=workflow%3ATest+event%3Apush+branch%3Amain" target="_blank">
10+
<img src="https://github.com/fastapi/sqlmodel/actions/workflows/test.yml/badge.svg?event=push&branch=main" alt="Test">
1111
</a>
1212
<a href="https://github.com/fastapi/sqlmodel/actions?query=workflow%3APublish" target="_blank">
13-
<img src="https://github.com/fastapi/sqlmodel/workflows/Publish/badge.svg" alt="Publish">
13+
<img src="https://github.com/fastapi/sqlmodel/actions/workflows/publish.yml/badge.svg" alt="Publish">
1414
</a>
1515
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/sqlmodel" target="_blank">
1616
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/sqlmodel.svg" alt="Coverage">

‎docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<em>SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.</em>
1313
</p>
1414
<p align="center">
15-
<a href="https://github.com/fastapi/sqlmodel/actions?query=workflow%3ATest" target="_blank">
16-
<img src="https://github.com/fastapi/sqlmodel/workflows/Test/badge.svg" alt="Test">
15+
<a href="https://github.com/fastapi/sqlmodel/actions?query=workflow%3ATest+event%3Apush+branch%3Amain" target="_blank">
16+
<img src="https://github.com/fastapi/sqlmodel/actions/workflows/test.yml/badge.svg?event=push&branch=main" alt="Test">
1717
</a>
1818
<a href="https://github.com/fastapi/sqlmodel/actions?query=workflow%3APublish" target="_blank">
19-
<img src="https://github.com/fastapi/sqlmodel/workflows/Publish/badge.svg" alt="Publish">
19+
<img src="https://github.com/fastapi/sqlmodel/actions/workflows/publish.yml/badge.svg" alt="Publish">
2020
</a>
2121
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/sqlmodel" target="_blank">
2222
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/sqlmodel.svg" alt="Coverage">

‎docs/release-notes.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,46 @@
22

33
## Latest Changes
44

5+
### Upgrades
6+
7+
* ⬆️ Drop support for Python 3.7, require Python 3.8 or above. PR [#1316](https://github.com/fastapi/sqlmodel/pull/1316) by [@svlandeg](https://github.com/svlandeg).
8+
9+
### Docs
10+
11+
* ✏️ Update `docs/virtual-environments.md`. PR [#1321](https://github.com/fastapi/sqlmodel/pull/1321) by [@sylvainHellin](https://github.com/sylvainHellin).
12+
13+
### Internal
14+
15+
*[pre-commit.ci] pre-commit autoupdate. PR [#1327](https://github.com/fastapi/sqlmodel/pull/1327) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
16+
* ⬆ Bump jinja2 from 3.1.4 to 3.1.6. PR [#1317](https://github.com/fastapi/sqlmodel/pull/1317) by [@dependabot[bot]](https://github.com/apps/dependabot).
17+
*[pre-commit.ci] pre-commit autoupdate. PR [#1319](https://github.com/fastapi/sqlmodel/pull/1319) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
18+
19+
## 0.0.24
20+
21+
### Upgrades
22+
23+
* ⬆️ Add support for Python 3.13. PR [#1289](https://github.com/fastapi/sqlmodel/pull/1289) by [@svlandeg](https://github.com/svlandeg).
24+
25+
### Internal
26+
27+
*[pre-commit.ci] pre-commit autoupdate. PR [#1114](https://github.com/fastapi/sqlmodel/pull/1114) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
28+
* ⬆ Bump ruff from 0.6.2 to 0.9.6. PR [#1294](https://github.com/fastapi/sqlmodel/pull/1294) by [@dependabot[bot]](https://github.com/apps/dependabot).
29+
30+
## 0.0.23
31+
32+
### Fixes
33+
34+
* 🐛 Fix type annotation in `Field` constructor. PR [#1304](https://github.com/fastapi/sqlmodel/pull/1304) by [@AlanBogarin](https://github.com/AlanBogarin).
35+
* 🐛 Fix Pydantic version check for version 2.10.x onwards. PR [#1255](https://github.com/fastapi/sqlmodel/pull/1255) by [@asiunov](https://github.com/asiunov).
36+
537
### Refactors
638

739
* 🚨 Fix types for new Pydantic. PR [#1131](https://github.com/fastapi/sqlmodel/pull/1131) by [@tiangolo](https://github.com/tiangolo).
840

941
### Docs
1042

43+
* 🩺 Take the GH badge only from pushes to the `main` branch. PR [#1291](https://github.com/fastapi/sqlmodel/pull/1291) by [@svlandeg](https://github.com/svlandeg).
44+
* 📝 Update documentation to refer to `list` instead of `List`. PR [#1147](https://github.com/fastapi/sqlmodel/pull/1147) by [@bubbletroubles](https://github.com/bubbletroubles).
1145
* ✏️ Fix typo in `databases.md`. PR [#1113](https://github.com/fastapi/sqlmodel/pull/1113) by [@radi-dev](https://github.com/radi-dev).
1246
* ✏️ Fix typo in `docs/tutorial/create-db-and-table.md`. PR [#1252](https://github.com/fastapi/sqlmodel/pull/1252) by [@ArianHamdi](https://github.com/ArianHamdi).
1347
* ✏️ Fix typo in `insert.md`. PR [#1256](https://github.com/fastapi/sqlmodel/pull/1256) by [@Noushadaliam](https://github.com/Noushadaliam).
@@ -22,6 +56,7 @@
2256

2357
### Internal
2458

59+
* ⬆ Bump pypa/gh-action-pypi-publish from 1.12.3 to 1.12.4. PR [#1277](https://github.com/fastapi/sqlmodel/pull/1277) by [@dependabot[bot]](https://github.com/apps/dependabot).
2560
* 💚 Fix CI test suite for Python 3.7. PR [#1309](https://github.com/fastapi/sqlmodel/pull/1309) by [@svlandeg](https://github.com/svlandeg).
2661
* 👷 Revert "Add Codecov to CI, Smokeshow/Cloudflare has been flaky lately (#1303)". PR [#1306](https://github.com/fastapi/sqlmodel/pull/1306) by [@svlandeg](https://github.com/svlandeg).
2762
* 👷 Add Codecov to CI, Smokeshow/Cloudflare has been flaky lately. PR [#1303](https://github.com/fastapi/sqlmodel/pull/1303) by [@tiangolo](https://github.com/tiangolo).

‎docs/tutorial/automatic-id-none-refresh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ And as we created the **engine** with `echo=True`, we can see the SQL statements
342342

343343
////
344344

345-
//// tab | Python 3.7+
345+
//// tab | Python 3.8+
346346

347347
```Python
348348
{!./docs_src/tutorial/automatic_id_none_refresh/tutorial002.py!}

‎docs/tutorial/code-structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ And this ends up *requiring* the same **circular imports** that are not supporte
183183

184184
But these **type annotations** we want to declare are not needed at *runtime*.
185185

186-
In fact, remember that we used `List["Hero"]`, with a `"Hero"` in a string?
186+
In fact, remember that we used `list["Hero"]`, with a `"Hero"` in a string?
187187

188188
For Python, at runtime, that is **just a string**.
189189

‎docs/tutorial/create-db-and-table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Now, let's give the code a final look:
562562

563563
////
564564

565-
//// tab | Python 3.7+
565+
//// tab | Python 3.8+
566566

567567
```{.python .annotate}
568568
{!./docs_src/tutorial/create_db_and_table/tutorial003.py!}

‎docs/tutorial/delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Now let's review all that code:
227227

228228
////
229229

230-
//// tab | Python 3.7+
230+
//// tab | Python 3.8+
231231

232232
```{ .python .annotate hl_lines="72-90" }
233233
{!./docs_src/tutorial/delete/tutorial002.py!}

‎docs/tutorial/fastapi/response-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ For example, we can pass the same `Hero` **SQLModel** class (because it is also
3838

3939
We can also use other type annotations, the same way we can use with Pydantic fields. For example, we can pass a list of `Hero`s.
4040

41-
First, we import `List` from `typing` and then we declare the `response_model` with `List[Hero]`:
41+
To do so, we declare the `response_model` with `list[Hero]`:
4242

4343
{* ./docs_src/tutorial/fastapi/response_model/tutorial001_py310.py ln[40:44] hl[40] *}
4444

‎docs/tutorial/fastapi/tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Now we can run the tests with `pytest` and see the results:
356356
$ pytest
357357

358358
============= test session starts ==============
359-
platform linux -- Python 3.7.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
359+
platform linux -- Python 3.10.0, pytest-7.4.4, pluggy-1.5.0
360360
rootdir: /home/user/code/sqlmodel-tutorial
361361
<b>collected 7 items </b>
362362

‎docs/tutorial/insert.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This is the code we had to create the database and table, nothing new here:
3939

4040
////
4141

42-
//// tab | Python 3.7+
42+
//// tab | Python 3.8+
4343

4444
```{.python .annotate hl_lines="22" }
4545
{!./docs_src/tutorial/create_db_and_table/tutorial003.py[ln:1-20]!}
@@ -343,7 +343,7 @@ Let's focus on the new code:
343343

344344
////
345345

346-
//// tab | Python 3.7+
346+
//// tab | Python 3.8+
347347

348348
```{.python .annotate }
349349
{!./docs_src/tutorial/insert/tutorial003.py!}

‎docs/tutorial/many-to-many/create-models-with-link.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Let's see the `Team` model, it's almost identical as before, but with a little c
2828

2929
{* ./docs_src/tutorial/many_to_many/tutorial001_py310.py ln[9:14] hl[14] *}
3030

31-
The **relationship attribute `heroes`** is still a list of heroes, annotated as `List["Hero"]`. Again, we use `"Hero"` in quotes because we haven't declared that class yet by this point in the code (but as you know, editors and **SQLModel** understand that).
31+
The **relationship attribute `heroes`** is still a list of heroes, annotated as `list["Hero"]`. Again, we use `"Hero"` in quotes because we haven't declared that class yet by this point in the code (but as you know, editors and **SQLModel** understand that).
3232

3333
We use the same **`Relationship()`** function.
3434

@@ -46,7 +46,7 @@ We **removed** the previous `team_id` field (column) because now the relationshi
4646

4747
The relationship attribute is now named **`teams`** instead of `team`, as now we support multiple teams.
4848

49-
It is no longer an `Optional[Team]` but a list of teams, annotated as **`List[Team]`**.
49+
It is no longer an `Optional[Team]` but a list of teams, annotated as **`list[Team]`**.
5050

5151
We are using the **`Relationship()`** here too.
5252

‎docs/tutorial/relationship-attributes/define-relationships-attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ And in the `Team` class, the `heroes` attribute is annotated as a list of `Hero`
8686

8787
/// tip
8888

89-
There's a couple of things we'll check again in some of the next chapters, about the `List["Hero"]` and the `back_populates`.
89+
There's a couple of things we'll check again in some of the next chapters, about the `list["Hero"]` and the `back_populates`.
9090

9191
But for now, let's first see how to use these relationship attributes.
9292

‎docs/tutorial/relationship-attributes/type-annotation-strings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
## About the String in `List["Hero"]`
1+
## About the String in `list["Hero"]`
22

3-
In the first Relationship attribute, we declare it with `List["Hero"]`, putting the `Hero` in quotes instead of just normally there:
3+
In the first Relationship attribute, we declare it with `list["Hero"]`, putting the `Hero` in quotes instead of just normally there:
44

55
{* ./docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001_py310.py ln[1:19] hl[9] *}
66

7-
What's that about? Can't we just write it normally as `List[Hero]`?
7+
What's that about? Can't we just write it normally as `list[Hero]`?
88

99
By that point, in that line in the code, the Python interpreter **doesn't know of any class `Hero`**, and if we put it just there, it would try to find it unsuccessfully, and then fail. 😭
1010

‎docs/tutorial/select.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ Let's review the code up to this point:
273273

274274
////
275275

276-
//// tab | Python 3.7+
276+
//// tab | Python 3.8+
277277

278278
```{ .python .annotate }
279279
{!./docs_src/tutorial/select/tutorial002.py!}

‎docs/tutorial/update.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Now let's review all that code:
236236

237237
////
238238

239-
//// tab | Python 3.7+
239+
//// tab | Python 3.8+
240240

241241
```{ .python .annotate hl_lines="44-55" }
242242
{!./docs_src/tutorial/update/tutorial002.py!}
@@ -272,7 +272,7 @@ This also means that you can update several fields (attributes, columns) at once
272272

273273
////
274274

275-
//// tab | Python 3.7+
275+
//// tab | Python 3.8+
276276

277277
```{ .python .annotate hl_lines="15-17 19-21 23" }
278278
# Code above omitted 👆
@@ -296,7 +296,7 @@ This also means that you can update several fields (attributes, columns) at once
296296

297297
////
298298

299-
//// tab | Python 3.7+
299+
//// tab | Python 3.8+
300300

301301
```Python
302302
{!./docs_src/tutorial/update/tutorial004.py!}

‎docs/virtual-environments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ After activating the virtual environment, the `PATH` variable would look somethi
668668
/home/user/code/awesome-project/.venv/bin:/usr/bin:/bin:/usr/sbin:/sbin
669669
```
670670

671-
That means that the system will now start looking first look for programs in:
671+
That means that the system will now start looking first for programs in:
672672

673673
```plaintext
674674
/home/user/code/awesome-project/.venv/bin

‎pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "sqlmodel"
77
dynamic = ["version"]
88
description = "SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness."
99
readme = "README.md"
10-
requires-python = ">=3.7"
10+
requires-python = ">=3.8"
1111
authors = [
1212
{ name = "Sebastián Ramírez", email = "tiangolo@gmail.com" },
1313
]
@@ -20,12 +20,12 @@ classifiers = [
2020
"Intended Audience :: System Administrators",
2121
"License :: OSI Approved :: MIT License",
2222
"Programming Language :: Python :: 3 :: Only",
23-
"Programming Language :: Python :: 3.7",
2423
"Programming Language :: Python :: 3.8",
2524
"Programming Language :: Python :: 3.9",
2625
"Programming Language :: Python :: 3.10",
2726
"Programming Language :: Python :: 3.11",
2827
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
2929
"Topic :: Database",
3030
"Topic :: Database :: Database Engines/Servers",
3131
"Topic :: Internet",

‎requirements-docs.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pillow==11.0.0
1111
# For image processing by Material for MkDocs
1212
cairosvg==2.7.1
1313
# mkdocstrings[python]==0.25.1
14-
# Enable griffe-typingdoc once dropping Python 3.7 and upgrading typing-extensions
15-
# griffe-typingdoc==0.2.5
14+
griffe-typingdoc==0.2.5
1615
# For griffe, it formats with black
1716
typer == 0.12.3
1817
mkdocs-macros-plugin==1.0.5

‎requirements-tests.txt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
pytest >=7.0.1,<8.0.0
44
coverage[toml] >=6.2,<8.0
55
mypy ==1.4.1
6-
ruff ==0.6.2
6+
ruff ==0.9.6
77
# For FastAPI tests
88
fastapi >=0.103.2
99
httpx ==0.24.1
10-
# TODO: upgrade when deprecating Python 3.7
11-
dirty-equals ==0.6.0
12-
jinja2 ==3.1.4
13-
# Pin typing-extensions until Python 3.8 is deprecated or the issue with dirty-equals
14-
# is fixed, maybe fixed after dropping Python 3.7 and upgrading dirty-equals
15-
typing-extensions ==4.6.1
10+
dirty-equals ==0.9.0
11+
jinja2 ==3.1.6
12+
typing-extensions ==4.12.2

‎sqlmodel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.0.22"
1+
__version__ = "0.0.24"
22

33
# Re-export from SQLAlchemy
44
from sqlalchemy.engine import create_engine as create_engine

‎sqlmodel/_compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
# Reassign variable to make it reexported for mypy
2929
PYDANTIC_VERSION = P_VERSION
30-
IS_PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
30+
PYDANTIC_MINOR_VERSION = tuple(int(i) for i in P_VERSION.split(".")[:2])
31+
IS_PYDANTIC_V2 = PYDANTIC_MINOR_VERSION[0] == 2
3132

3233

3334
if TYPE_CHECKING:

0 commit comments

Comments
 (0)