Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Aug 8, 2023
2 parents 981e2f6 + 0c81200 commit fce4edf
Show file tree
Hide file tree
Showing 26 changed files with 2,118 additions and 2,084 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
TORTOISE_MSSQL_DRIVER: ODBC Driver 18 for SQL Server
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/cache@v3
with:
Expand Down
19 changes: 17 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ Changelog

.. rst-class:: emphasize-children

0.19
0.20
====
0.19.4

0.20.0
------
Added
^^^^^
- Enhancement for FastAPI lifespan support (#1371)
- Allow ForeignKeyField(on_delete=NO_ACTION) (#1393)
- Support `pydantic` 2.0. (#1433)

Fixed
^^^^^
- Fix foreign key constraint not generated on MSSQL Server. (#1400)
- Fix testcase error with python3.11 (#1308)

Breaking Changes
^^^^^^^^^^^^^^^^
- Drop support for `pydantic` 1.x.
- Drop support for `python` 3.7.
- Param `config_class` of `pydantic_model_creator` is renamed to `model_config`.
- Attr `config_class` of `PydanticMeta` is renamed to `model_config`.

0.19
====

0.19.3
------
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ You can find the docs at `Documentation <https://tortoise.github.io>`_
Tortoise ORM is a young project and breaking changes are to be expected.
We keep a `Changelog <https://tortoise.github.io/CHANGELOG.html>`_ and it will have possible breakage clearly documented.

Tortoise ORM is supported on CPython >= 3.7 for SQLite, MySQL and PostgreSQL and Microsoft SQL Server and Oracle.
Tortoise ORM is supported on CPython >= 3.8 for SQLite, MySQL and PostgreSQL and Microsoft SQL Server and Oracle.

Why was Tortoise ORM built?
---------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Tortoise ORM follows a the following agreed upon style:
* Always try to separate out terms clearly rather than concatenate words directly:
* ``some_purpose`` instead of ``somepurpose``
* ``SomePurpose`` instead of ``Somepurpose``
* Keep in mind the targeted Python versions of ``>=3.7``:
* Keep in mind the targeted Python versions of ``>=3.8``:
* Do use f-strings
* Please try and provide type annotations where you can, it will improve auto-completion in editors, and better static analysis.

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It's engraved in it's design that you are working not with just tables, you work

Source & issue trackers are available at `<https://github.com/tortoise/tortoise-orm/>`_

Tortoise ORM is supported on CPython >= 3.7 for SQLite, MySQL and PostgreSQL.
Tortoise ORM is supported on CPython >= 3.8 for SQLite, MySQL and PostgreSQL.

Introduction
============
Expand Down
44 changes: 22 additions & 22 deletions examples/fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@
from contextlib import asynccontextmanager
from typing import List

from fastapi import FastAPI, HTTPException
from fastapi import FastAPI
from models import User_Pydantic, UserIn_Pydantic, Users
from pydantic import BaseModel
from starlette.exceptions import HTTPException

from tortoise.contrib.fastapi import HTTPNotFoundError, register_tortoise
from tortoise.contrib.fastapi import register_tortoise


@asynccontextmanager
async def lifespan(app: FastAPI):
"""It is recommended to register tortoise use async with.

Or in the traditional, procedural manner::

db = await register_tortoise(
app,
db_url="sqlite://:memory:",
modules={"models": ["models"]},
generate_schemas=True,
add_exception_handlers=True,
is_lifespan=True,
)
yield
await db.close()

"""
async with register_tortoise(
app,
db_url="sqlite://:memory:",
Expand All @@ -20,19 +37,6 @@ async def lifespan(app: FastAPI):
is_lifespan=True,
):
yield
"""
# or in the traditional, procedural manner::
db = await register_tortoise(
app,
db_url="sqlite://:memory:",
modules={"models": ["models"]},
generate_schemas=True,
add_exception_handlers=True,
is_lifespan=True,
)
yield
await db.close()
"""


app = FastAPI(title="Tortoise ORM FastAPI example", lifespan=lifespan)
Expand All @@ -53,22 +57,18 @@ async def create_user(user: UserIn_Pydantic):
return await User_Pydantic.from_tortoise_orm(user_obj)


@app.get(
"/user/{user_id}", response_model=User_Pydantic, responses={404: {"model": HTTPNotFoundError}}
)
@app.get("/user/{user_id}", response_model=User_Pydantic)
async def get_user(user_id: int):
return await User_Pydantic.from_queryset_single(Users.get(id=user_id))


@app.put(
"/user/{user_id}", response_model=User_Pydantic, responses={404: {"model": HTTPNotFoundError}}
)
@app.put("/user/{user_id}", response_model=User_Pydantic)
async def update_user(user_id: int, user: UserIn_Pydantic):
await Users.filter(id=user_id).update(**user.dict(exclude_unset=True))
return await User_Pydantic.from_queryset_single(Users.get(id=user_id))


@app.delete("/user/{user_id}", response_model=Status, responses={404: {"model": HTTPNotFoundError}})
@app.delete("/user/{user_id}", response_model=Status)
async def delete_user(user_id: int):
deleted_count = await Users.filter(id=user_id).delete()
if not deleted_count:
Expand Down
10 changes: 5 additions & 5 deletions examples/pydantic/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Address(Model):
created_at = fields.DatetimeField(auto_now_add=True)

event: fields.OneToOneRelation[Event] = fields.OneToOneField(
"models.Event", on_delete=fields.CASCADE, related_name="address", pk=True
"models.Event", on_delete=fields.OnDelete.CASCADE, related_name="address", pk=True
)

class Meta:
Expand Down Expand Up @@ -87,16 +87,16 @@ async def run():
await event3.participants.add(team1, team3)

p = await Event_Pydantic.from_tortoise_orm(await Event.get(name="Test"))
print("One Event:", p.json(indent=4))
print("One Event:", p.model_dump_json(indent=4))

p = await Tournament_Pydantic.from_tortoise_orm(await Tournament.get(name="New Tournament"))
print("One Tournament:", p.json(indent=4))
print("One Tournament:", p.model_dump_json(indent=4))

p = await Team_Pydantic.from_tortoise_orm(await Team.get(name="Onesies"))
print("One Team:", p.json(indent=4))
print("One Team:", p.model_dump_json(indent=4))

pl = await Event_Pydantic_List.from_queryset(Event.filter(address__event_id__isnull=True))
print("All Events without addresses:", pl.json(indent=4))
print("All Events without addresses:", pl.model_dump_json(indent=4))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Address(Model):
street = fields.CharField(max_length=128)

event: fields.OneToOneRelation[Event] = fields.OneToOneField(
"models.Event", on_delete=fields.CASCADE, related_name="address", pk=True
"models.Event", on_delete=fields.OnDelete.CASCADE, related_name="address", pk=True
)

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion examples/relations_with_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Principal(Model):
id = fields.IntField(pk=True)
name = fields.TextField()
school: fields.OneToOneRelation[School] = fields.OneToOneField(
"models.School", on_delete=fields.CASCADE, related_name="principal", to_field="id"
"models.School", on_delete=fields.OnDelete.CASCADE, related_name="principal", to_field="id"
)


Expand Down
Loading

0 comments on commit fce4edf

Please sign in to comment.