Skip to content

Commit c995b5a

Browse files
committed
some type checking fixes to satisfy sqlalchemy2-stubs, README additions
1 parent 57ae5b4 commit c995b5a

8 files changed

Lines changed: 33 additions & 17 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Generate a backend and frontend stack using Python, including interactive API documentation.
66

7+
** This is a fork of [tiangolo/full-stack-fastapi-postgresql](https://github.com/tiangolo/full-stack-fastapi-postgresql), which hasn't seen an update in a while **
8+
79
### Interactive API documentation
810

911
[![API docs](img/docs.png)](https://github.com/tiangolo/full-stack-fastapi-postgresql)
@@ -143,7 +145,17 @@ After using this generator, your new project (the directory created) will contai
143145

144146
## Release Notes
145147

146-
### Latest Changes
148+
### 0.6.0
149+
150+
* Updated to python 3.10
151+
* Updated backend dependencies
152+
* Updated frontend dependencies where possible
153+
* Refactored frontend to support Vuetify 2 and Vee-Validate 3, using [165](https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/165) as a guide (also included the eslint and prettier additions)
154+
* Incorporated the steps in [tiangolo/uvicorn-gunicorn-docker](https://github.com/tiangolo/uvicorn-gunicorn-docker) into `backend.dockerfile`, so that the update to python 3.10 was possible. `start.sh`, `start-reload.sh`, and `gunicorn_conf.py` from that repo were added to backend
155+
* Updated the base image for the build stage in the frontend `Dockerfile` to `node:18`, no longer the outdated [tiangolo/node-frontend](https://github.com/tiangolo/node-frontend)
156+
* A handfuls of issue fixes
157+
158+
### Below changes are from tiangolo/full-stack-fastapi-postgresql
147159

148160
* Update issue-manager. PR [#211](https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/211).
149161
* Add [GitHub Sponsors](https://github.com/sponsors/tiangolo) button. PR [#201](https://github.com/tiangolo/full-stack-fastapi-postgresql/pull/201).

{{cookiecutter.project_slug}}/backend/app/app/backend_pre_start.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from sqlalchemy import text
34
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
45

56
from app.db.session import SessionLocal
@@ -21,7 +22,7 @@ def init() -> None:
2122
try:
2223
db = SessionLocal()
2324
# Try to create session to check if DB is awake
24-
db.execute("SELECT 1")
25+
db.execute(text("SELECT 1"))
2526
except Exception as e:
2627
logger.error(e)
2728
raise e

{{cookiecutter.project_slug}}/backend/app/app/celeryworker_pre_start.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from sqlalchemy import text
34
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
45

56
from app.db.session import SessionLocal
@@ -21,7 +22,7 @@ def init() -> None:
2122
try:
2223
# Try to create session to check if DB is awake
2324
db = SessionLocal()
24-
db.execute("SELECT 1")
25+
db.execute(text("SELECT 1"))
2526
except Exception as e:
2627
logger.error(e)
2728
raise e

{{cookiecutter.project_slug}}/backend/app/app/crud/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union
1+
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar, Union, cast
22

33
from fastapi.encoders import jsonable_encoder
44
from pydantic import BaseModel
@@ -60,7 +60,8 @@ def update(
6060
return db_obj
6161

6262
def remove(self, db: Session, *, id: int) -> ModelType:
63-
obj = db.query(self.model).get(id)
63+
obj = db.get(self.model, id)
64+
assert obj is not None
6465
db.delete(obj)
6566
db.commit()
66-
return obj
67+
return cast(ModelType, obj)

{{cookiecutter.project_slug}}/backend/app/app/db/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
from app.core.config import settings
55

6-
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
6+
engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI), pool_pre_ping=True)
77
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

{{cookiecutter.project_slug}}/backend/app/app/models/item.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111

1212
class Item(Base):
13-
id = Column(Integer, primary_key=True, index=True)
13+
id: int = Column(Integer, primary_key=True, index=True)
1414
title = Column(String, index=True)
1515
description = Column(String, index=True)
1616
owner_id = Column(Integer, ForeignKey("user.id"))
17-
owner = relationship("User", back_populates="items")
17+
owner: User = relationship("User", back_populates="items")
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING
1+
from typing import TYPE_CHECKING, List
22

33
from sqlalchemy import Boolean, Column, Integer, String
44
from sqlalchemy.orm import relationship
@@ -10,10 +10,10 @@
1010

1111

1212
class User(Base):
13-
id = Column(Integer, primary_key=True, index=True)
13+
id: int = Column(Integer, primary_key=True, index=True)
1414
full_name = Column(String, index=True)
15-
email = Column(String, unique=True, index=True, nullable=False)
16-
hashed_password = Column(String, nullable=False)
17-
is_active = Column(Boolean(), default=True)
18-
is_superuser = Column(Boolean(), default=False)
19-
items = relationship("Item", back_populates="owner")
15+
email: str = Column(String, unique=True, index=True, nullable=False)
16+
hashed_password: str = Column(String, nullable=False)
17+
is_active: bool = Column(Boolean(), default=True)
18+
is_superuser: bool = Column(Boolean(), default=False)
19+
items: List[Item] = relationship("Item", back_populates="owner")

{{cookiecutter.project_slug}}/backend/app/app/tests_pre_start.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from sqlalchemy import text
34
from tenacity import after_log, before_log, retry, stop_after_attempt, wait_fixed
45

56
from app.db.session import SessionLocal
@@ -21,7 +22,7 @@ def init() -> None:
2122
try:
2223
# Try to create session to check if DB is awake
2324
db = SessionLocal()
24-
db.execute("SELECT 1")
25+
db.execute(text("SELECT 1"))
2526
except Exception as e:
2627
logger.error(e)
2728
raise e

0 commit comments

Comments
 (0)