Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

✨ Upgrade SQLAlchemy to 2.0, including initial work by farahats9 #700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
60318b4
migration to sqlalchemy 2.0
farahats9 Mar 7, 2023
48ddc61
fix some linting errors
farahats9 Mar 24, 2023
b48423f
remove unused imports
farahats9 Mar 24, 2023
9c219d9
Update sqlmodel/sql/expression.py
farahats9 Mar 31, 2023
37ed979
reflecting python 3.6 deprecation in docs and tests
farahats9 Mar 31, 2023
0eee8e8
Merge branch 'main' of https://github.com/farahats9/sqlmodel
farahats9 Mar 31, 2023
050cf02
resolving @sbor23 comments
farahats9 Mar 31, 2023
fbff99c
add the new Subquery class
farahats9 Apr 30, 2023
6d8f527
update to latest sqlalchemy version
farahats9 Apr 30, 2023
4ce8d07
fix jinja2 template
farahats9 Apr 30, 2023
ecfb321
`Result` expects a type `Tuple[_T]`
peterlandry Jul 26, 2023
3738a7f
Remove unused type ignore
peterlandry Jul 26, 2023
814988b
Result seems well enough typed in SqlAlchemy now we can simply shim over
peterlandry Jul 26, 2023
118ca33
Implicit export of ForwardRef was remove in pydantic
peterlandry Jul 26, 2023
9170729
_Select expects a `Tuple[Any, ...]`
peterlandry Jul 26, 2023
7f5ba1c
Use Dict type instead of Mapping for SqlAlchemy compat
peterlandry Jul 26, 2023
e942e5e
Execution options are not Optional in SA
peterlandry Jul 26, 2023
ef9f00a
Another instance of non-optional execution_options
peterlandry Jul 26, 2023
643cea5
Fix Tuple in jinja template as well
peterlandry Jul 26, 2023
b89adbb
Use ForUpdateArg from sqlalchemy
peterlandry Jul 26, 2023
eff0803
Fix signature for `Session.get`
peterlandry Jul 26, 2023
c5bdbcc
Merge pull request #2 from peterlandry/main
farahats9 Jul 27, 2023
1752f0b
formatting and remove unused type
farahats9 Jul 27, 2023
b4f4a4f
🔀 Merge branch 'main' into sa2-a
tiangolo Nov 7, 2023
4d264a3
📝 Do not claim Python 3.11 yet, this will be done in a subsequent PR
tiangolo Nov 7, 2023
5f52693
🔥 Remove no longer necessary engine module, it was only to provide ty…
tiangolo Nov 7, 2023
0468d6f
⏪️ Revert altering tutorial, avoiding lack of support for forward ref…
tiangolo Nov 17, 2023
fcb92a0
🐛 Fix support for forward references in relationships
tiangolo Nov 17, 2023
f02584b
✅ Update tests for newest FastAPI with OpenAPI 3.1.0
tiangolo Nov 17, 2023
f4127d2
⏪️ Revert altering tutorial to accomodate for the previous lack of su…
tiangolo Nov 17, 2023
50cb798
✨ Update and refactor expression (and template) with new types from S…
tiangolo Nov 17, 2023
2083ba6
🎨 Update type annotation in sqltypes.py
tiangolo Nov 17, 2023
8672bfa
♻️ Refactor generation of expression.py with template
tiangolo Nov 17, 2023
b433b7d
✨ Update Session types and logic, add deprecations for discouraged me…
tiangolo Nov 17, 2023
4ada203
✨ Update import and export locations
tiangolo Nov 17, 2023
aa27b2b
🔧 Update mypy config for docs_src
tiangolo Nov 17, 2023
baa5e3a
⬆️ Update SQLAlchemy dependency pin
tiangolo Nov 17, 2023
80a5c52
✨ Update AsyncSession with support for SQLAlchemy 2.0 and new Session
tiangolo Nov 17, 2023
61f6a1f
✨ Add some new re-exported objects from SQLAlchemy
tiangolo Nov 18, 2023
7e9971d
♻️ Update type annotations of expression.py to support old Pythons
tiangolo Nov 18, 2023
62327ce
⬆️ Upgrade FastAPI and HTTPX dependency for tests
tiangolo Nov 18, 2023
40beca9
Merge branch 'main' into sa2-a
tiangolo Nov 18, 2023
be5277e
🔇 Do not run mypy on Python 3.7 as it behaves differently
tiangolo Nov 18, 2023
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
Prev Previous commit
Next Next commit
🔀 Merge branch 'main' into sa2-a
  • Loading branch information
tiangolo committed Nov 7, 2023
commit b4f4a4f6fe7d20111efe88e535e77abac8fd1e76
6 changes: 5 additions & 1 deletion 6 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion 2 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ It combines SQLAlchemy and Pydantic and tries to simplify the code you write as

## Requirements

A recent and currently supported version of Python (right now, <a href="https://www.python.org/downloads/" class="external-link" target="_blank">Python supports versions 3.7 and above</a>).
A recent and currently supported <a href="https://www.python.org/downloads/" class="external-link" target="_blank">version of Python</a>.

As **SQLModel** is based on **Pydantic** and **SQLAlchemy**, it requires them. They will be automatically installed when you install SQLModel.

Expand Down
4 changes: 0 additions & 4 deletions 4 docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ First, you might want to see the basic ways to [help SQLModel and get help](help

If you already cloned the repository and you know that you need to deep dive in the code, here are some guidelines to set up your environment.

### Python

SQLModel supports Python 3.7 and above.

### Poetry

**SQLModel** uses <a href="https://python-poetry.org/" class="external-link" target="_blank">Poetry</a> to build, package, and publish the project.
Expand Down
2 changes: 1 addition & 1 deletion 2 docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Nevertheless, SQLModel is completely **independent** of FastAPI and can be used

## Just Modern Python

It's all based on standard <abbr title="Python currently supported versions, 3.7 and above.">modern **Python**</abbr> type annotations. No new syntax to learn. Just standard modern Python.
It's all based on standard <abbr title="Currently supported versions of Python">modern **Python**</abbr> type annotations. No new syntax to learn. Just standard modern Python.

If you need a 2 minute refresher of how to use Python types (even if you don't use SQLModel or FastAPI), check the FastAPI tutorial section: <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">Python types intro</a>.

Expand Down
2 changes: 1 addition & 1 deletion 2 docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ It combines SQLAlchemy and Pydantic and tries to simplify the code you write as

## Requirements

A recent and currently supported version of Python (right now, <a href="https://www.python.org/downloads/" class="external-link" target="_blank">Python supports versions 3.7 and above</a>).
A recent and currently supported <a href="https://www.python.org/downloads/" class="external-link" target="_blank">version of Python</a>.

As **SQLModel** is based on **Pydantic** and **SQLAlchemy**, it requires them. They will be automatically installed when you install SQLModel.

Expand Down
3 changes: 0 additions & 3 deletions 3 docs/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ $ cd sqlmodel-tutorial

Make sure you have an officially supported version of Python.

Currently it is **Python 3.7** and above (Python 3.6 was already deprecated).

You can check which version you have with:

<div class="termy">
Expand All @@ -85,7 +83,6 @@ You might want to try with the specific versions, for example with:
* `python3.10`
* `python3.9`
* `python3.8`
* `python3.7`

The code would look like this:

Expand Down
10 changes: 3 additions & 7 deletions 10 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Database",
"Topic :: Database :: Database Engines/Servers",
"Topic :: Internet",
Expand All @@ -32,8 +31,8 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.7"
SQLAlchemy = ">=2.0.0,<=2.0.11"
pydantic = "^1.8.2"
SQLAlchemy = ">=2.0.0,<=2.1.0"
pydantic = "^1.9.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.1"
Expand All @@ -47,10 +46,7 @@ mdx-include = "^1.4.1"
coverage = {extras = ["toml"], version = ">=6.2,<8.0"}
fastapi = "^0.68.1"
requests = "^2.26.0"
autoflake = "^1.4"
isort = "^5.9.3"
async_generator = {version = "*", python = "~3.7"}
async-exit-stack = {version = "*", python = "~3.7"}
ruff = "^0.1.2"

[build-system]
requires = ["poetry-core"]
Expand Down
5 changes: 2 additions & 3 deletions 5 scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ set -e
set -x

mypy sqlmodel
flake8 sqlmodel tests docs_src
black sqlmodel tests docs_src --check
isort sqlmodel tests docs_src scripts --check-only
ruff sqlmodel tests docs_src scripts
ruff format sqlmodel tests docs_src --check
2 changes: 1 addition & 1 deletion 2 sqlmodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from sqlalchemy.sql import (
LABEL_STYLE_TABLENAME_PLUS_COL as LABEL_STYLE_TABLENAME_PLUS_COL,
)
from sqlalchemy.sql import Subquery as Subquery
from sqlalchemy.sql import alias as alias
from sqlalchemy.sql import all_ as all_
from sqlalchemy.sql import and_ as and_
Expand Down Expand Up @@ -70,7 +71,6 @@
from sqlalchemy.sql import outerjoin as outerjoin
from sqlalchemy.sql import outparam as outparam
from sqlalchemy.sql import over as over
from sqlalchemy.sql import Subquery as Subquery
from sqlalchemy.sql import table as table
from sqlalchemy.sql import tablesample as tablesample
from sqlalchemy.sql import text as text
Expand Down
1 change: 0 additions & 1 deletion 1 sqlmodel/orm/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from sqlalchemy.orm import Session as _Session
from sqlalchemy.sql.base import Executable as _Executable
from sqlalchemy.sql.selectable import ForUpdateArg as _ForUpdateArg
from sqlmodel.sql.expression import Select, SelectOfScalar

from ..engine.result import Result, ScalarResult
from ..sql.base import Executable
Expand Down
5 changes: 2 additions & 3 deletions 5 sqlmodel/sql/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import (
TYPE_CHECKING,
Any,
Generic,
Mapping,
Sequence,
Tuple,
Expand All @@ -23,15 +22,15 @@
_TSelect = TypeVar("_TSelect")


class Select(_Select[Tuple[_TSelect]], Generic[_TSelect]):
class Select(_Select[Tuple[_TSelect]]):
inherit_cache = True


# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
# entity, so the result will be converted to a scalar by default. This way writing
# for loops on the results will feel natural.
class SelectOfScalar(_Select[Tuple[_TSelect]], Generic[_TSelect]):
class SelectOfScalar(_Select[Tuple[_TSelect]]):
inherit_cache = True


Expand Down
11 changes: 2 additions & 9 deletions 11 sqlmodel/sql/expression.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ from datetime import datetime
from typing import (
TYPE_CHECKING,
Any,
Generic,
Mapping,
Sequence,
Tuple,
Expand All @@ -20,22 +19,16 @@ from sqlalchemy.sql.expression import Select as _Select

_TSelect = TypeVar("_TSelect")

class Select(_Select[Tuple[_TSelect]], Generic[_TSelect]):
class Select(_Select[Tuple[_TSelect]]):
inherit_cache = True

# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
# entity, so the result will be converted to a scalar by default. This way writing
# for loops on the results will feel natural.
class SelectOfScalar(_Select[Tuple[_TSelect]], Generic[_TSelect]):
class SelectOfScalar(_Select[Tuple[_TSelect]]):
inherit_cache = True

# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different
# purpose. This is the same as a normal SQLAlchemy Select class where there's only one
# entity, so the result will be converted to a scalar by default. This way writing
# for loops on the results will feel natural.
class SelectOfScalar(_Select, Generic[_TSelect]):
inherit_cache = True

if TYPE_CHECKING: # pragma: no cover
from ..main import SQLModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ def test_tutorial(clear_sqlmodel):
expected_indexes = [
{
"name": "ix_hero_name",
"dialect_options": {},
"column_names": ["name"],
"unique": 0,
"dialect_options": {},
},
{
"name": "ix_hero_age",
"dialect_options": {},
"column_names": ["age"],
"unique": 0,
"dialect_options": {},
},
]
for index in expected_indexes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ def test_tutorial(clear_sqlmodel):
expected_indexes = [
{
"name": "ix_hero_age",
"dialect_options": {},
"column_names": ["age"],
"unique": 0,
"dialect_options": {},
},
{
"name": "ix_hero_name",
"dialect_options": {},
"column_names": ["name"],
"unique": 0,
"dialect_options": {},
},
]
for index in expected_indexes:
Expand Down
4 changes: 2 additions & 2 deletions 4 tests/test_tutorial/test_indexes/test_tutorial001.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def test_tutorial(clear_sqlmodel):
expected_indexes = [
{
"name": "ix_hero_name",
"dialect_options": {},
"column_names": ["name"],
"unique": 0,
"dialect_options": {},
},
{
"name": "ix_hero_age",
"dialect_options": {},
"column_names": ["age"],
"unique": 0,
"dialect_options": {},
},
]
for index in expected_indexes:
Expand Down
4 changes: 2 additions & 2 deletions 4 tests/test_tutorial/test_indexes/test_tutorial006.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def test_tutorial(clear_sqlmodel):
expected_indexes = [
{
"name": "ix_hero_name",
"dialect_options": {},
"column_names": ["name"],
"unique": 0,
"dialect_options": {},
},
{
"name": "ix_hero_age",
"dialect_options": {},
"column_names": ["age"],
"unique": 0,
"dialect_options": {},
},
]
for index in expected_indexes:
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.