Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit b59b702

Browse files
authored
Pydantic v2 (#15)
* Initial commit * Update requirements.txt * Fixing * Black * Update script_launch.py
1 parent fd12e09 commit b59b702

5 files changed

Lines changed: 12 additions & 15 deletions

File tree

app/routes/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
app.add_middleware(
1313
CORSMiddleware,
1414
allow_origins=settings.CORS_ALLOW_ORIGINS,
15-
allow_credentials=settings.CORS_ALLOW_CREDENTIALS,
16-
allow_methods=settings.CORS_ALLOW_METHODS,
17-
allow_headers=settings.CORS_ALLOW_HEADERS,
15+
allow_credentials=str(settings.CORS_ALLOW_CREDENTIALS),
16+
allow_methods=str(settings.CORS_ALLOW_METHODS),
17+
allow_headers=str(settings.CORS_ALLOW_HEADERS),
1818
)
1919

2020
app.include_router(script_router, prefix='', tags=['User'])

app/routes/models/base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from pydantic import BaseModel
1+
from pydantic import BaseModel, ConfigDict
22

33

44
class Base(BaseModel):
55
def __repr__(self) -> str:
66
attrs = []
7-
for k, v in self.__class__.schema().items():
7+
for k, v in self.__class__.model_json_schema().items():
88
attrs.append(f"{k}={v}")
99
return "{}({})".format(self.__class__.__name__, ', '.join(attrs))
1010

11-
class Config:
12-
orm_mode = True
11+
model_config = ConfigDict(from_attributes=True, extra="ignore")

app/routes/script_launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SendOutput(BaseModel):
2424
async def run_script(
2525
action: str,
2626
inp: Input,
27-
user: dict = Depends(UnionAuth(scopes=[] if settings.ALLOWED_SCOPE is None else [settings.ALLOWED_SCOPE]))
27+
user: dict = Depends(UnionAuth(scopes=[] if settings.ALLOWED_SCOPE is None else [settings.ALLOWED_SCOPE])),
2828
):
2929
"""runs a bash script, located in scripts/{action}. The script takes 2 arguments: git_ref and repo_url"""
3030

app/settings.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from functools import lru_cache
22

3-
from pydantic import AnyUrl, BaseSettings, PostgresDsn
3+
from pydantic import AnyUrl, ConfigDict, PostgresDsn
4+
from pydantic_settings import BaseSettings
45

56

67
class Settings(BaseSettings):
@@ -13,11 +14,7 @@ class Settings(BaseSettings):
1314
CORS_ALLOW_METHODS: list[str] = ['*']
1415
CORS_ALLOW_HEADERS: list[str] = ['*']
1516

16-
class Config:
17-
"""Pydantic BaseSettings config"""
18-
19-
case_sensitive = True
20-
env_file = ".env"
17+
model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore")
2118

2219

2320
@lru_cache

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fastapi
2-
pydantic[dotenv]
2+
pydantic
3+
pydantic_settings
34
uvicorn
45
gunicorn
56
auth_lib_profcomff[fastapi]

0 commit comments

Comments
 (0)