Skip to content

Commit e4db077

Browse files
committed
fix: remove supabase-py-async with supabase-py
1 parent 4f4a7f1 commit e4db077

14 files changed

Lines changed: 200 additions & 335 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"pydantic[email]>=2.8.2",
1515
"pydantic-settings>=2.4.0",
1616
"python-multipart>=0.0.9",
17-
"supabase-py-async",
17+
"supabase>=2.7.4",
1818
]
1919

2020
[project.optional-dependencies]

src/app/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
"""
2-
-*- coding: utf-8 -*-
3-
@Organization : SupaVision
4-
@Author : 18317
5-
@Date Created : 10/01/2024
6-
@Description :
7-
"""

src/app/api/deps.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
"""
2-
-*- coding: utf-8 -*-
3-
@Organization : SupaVision
4-
@Author : 18317
5-
@Date Created : 05/01/2024
6-
@Description :
7-
"""
8-
91
import logging
102
from typing import Annotated
113

124
from fastapi import Depends, HTTPException
135
from fastapi.security import OAuth2PasswordBearer
146
from gotrue.errors import AuthApiError
15-
from supabase_py_async import AsyncClient, create_client
16-
from supabase_py_async.lib.client_options import ClientOptions
7+
from supabase._async.client import AsyncClient, create_client
8+
from supabase.lib.client_options import ClientOptions
179

1810
from app.core.config import settings
1911
from app.schemas.auth import UserIn
@@ -62,9 +54,10 @@ async def get_db(user: CurrentUser) -> AsyncClient:
6254
client = await create_client(
6355
settings.SUPABASE_URL,
6456
settings.SUPABASE_KEY,
65-
access_token=user.access_token,
6657
options=ClientOptions(
67-
postgrest_client_timeout=10, storage_client_timeout=10
58+
postgrest_client_timeout=30,
59+
storage_client_timeout=30,
60+
headers={"Authorization": f"Bearer {user.access_token}"},
6861
),
6962
)
7063
# checks all done in supabase-py !
@@ -77,9 +70,6 @@ async def get_db(user: CurrentUser) -> AsyncClient:
7770
raise HTTPException(
7871
status_code=401, detail="Invalid authentication credentials"
7972
)
80-
finally:
81-
if client:
82-
await client.auth.sign_out()
8373

8474

8575
SessionDep = Annotated[AsyncClient, Depends(get_db)]

src/app/core/config.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""
2-
-*- coding: utf-8 -*-
3-
@Organization : SupaVision
4-
@Author : 18317
5-
@Date Created : 05/01/2024
6-
@Description :
7-
"""
8-
91
import logging
102
import os
113
from typing import ClassVar

src/app/crud/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""
2-
-*- coding: utf-8 -*-
3-
@Organization : SupaVision
4-
@Author : 18317
5-
@Date Created : 07/01/2024
6-
@Description :
7-
"""
8-
91
from .crud_item import item
102

113
# For a new basic set of CRUD operations you could just do

src/app/crud/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Generic, TypeVar
22

3-
from supabase_py_async import AsyncClient
3+
from supabase._async.client import AsyncClient
44

55
from app.schemas.auth import UserIn
66
from app.schemas.base import CreateBase, ResponseBase, UpdateBase

src/app/crud/crud_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from supabase_py_async import AsyncClient
1+
from supabase._async.client import AsyncClient
22

33
from app.crud.base import CRUDBase
44
from app.schemas import Item, ItemCreate, ItemUpdate

src/app/main.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""
2-
-*- coding: utf-8 -*-
3-
@Organization : SupaVision
4-
@Author : 18317
5-
@Date Created : 05/01/2024
6-
@Description :
7-
"""
8-
91
import uvicorn
102
from fastapi import FastAPI
113
from fastapi.middleware.cors import CORSMiddleware

src/app/schemas/base.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""
2-
-*- coding: utf-8 -*-
3-
@Organization : SupaVision
4-
@Author : 18317
5-
@Date Created : 11/01/2024
6-
@Description :
7-
"""
8-
91
from typing import ClassVar
102

113
from pydantic import BaseModel, ConfigDict

tests/api/api_v1/test_items.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
from faker import Faker
44
from starlette.testclient import TestClient
5-
from supabase_py_async import AsyncClient
5+
from supabase._async.client import AsyncClient
66

77
from app.schemas import Token
88
from tests.utils import get_auth_header
@@ -68,18 +68,15 @@ async def test_read_item_by_owner(
6868
headers = get_auth_header(token.access_token)
6969
test_data = Faker().sentence()
7070

71-
# 创建条目
7271
client.post(
7372
"/api/v1/items/create-item",
7473
headers=headers,
7574
json={"test_data": test_data},
7675
)
7776

78-
# 获取当前用户的ID
7977
user = await db.auth.get_user(jwt=token.access_token)
8078
user_id = user.user.id
8179

82-
# 按拥有者读取条目
8380
read_response = client.get(
8481
"/api/v1/items/get-by-owner",
8582
headers=headers,
@@ -118,7 +115,7 @@ async def test_update_item(client: TestClient, token: Token) -> None:
118115

119116
@pytest.mark.anyio
120117
async def test_delete_item(client: TestClient, token: Token) -> None:
121-
# 创建条目
118+
122119
headers = get_auth_header(token.access_token)
123120
test_data = Faker().sentence()
124121
create_response = client.post(
@@ -129,14 +126,12 @@ async def test_delete_item(client: TestClient, token: Token) -> None:
129126
assert create_response.status_code == 200
130127
created_item_id = create_response.json()["id"]
131128

132-
# 删除条目
133129
delete_response = client.delete(
134130
f"/api/v1/items/delete/{created_item_id}",
135131
headers=headers,
136132
)
137133
assert delete_response.status_code == 200
138134

139-
# 尝试获取删除的条目
140135
get_response = client.get(
141136
f"/api/v1/items/get-by-id/{created_item_id}",
142137
headers=headers,

0 commit comments

Comments
 (0)