Skip to content

Commit e87437b

Browse files
author
Benjamin PILIA
committed
fix idle_in_transaction
1 parent 22df402 commit e87437b

5 files changed

Lines changed: 15 additions & 28 deletions

File tree

api/clients/vector_store/_elasticsearchvectorstoreclient.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ async def create_collection(self, collection_id: int, vector_size: int) -> None:
4343

4444
mappings = {
4545
"dynamic_templates": [
46-
{
47-
"metadata_objects_disabled": {
48-
"path_match": "metadata.*",
49-
"match_mapping_type": "object",
50-
"mapping": {"enabled": False}
51-
}
52-
},
46+
{"metadata_objects_disabled": {"path_match": "metadata.*", "match_mapping_type": "object", "mapping": {"enabled": False}}},
5347
{
5448
"metadata_dates_by_name": {
5549
"path_match": "metadata.*",
@@ -58,38 +52,32 @@ async def create_collection(self, collection_id: int, vector_size: int) -> None:
5852
"mapping": {
5953
"type": "date",
6054
"ignore_malformed": True,
61-
"format": "strict_date_optional_time||strict_date_time||yyyy-MM-dd'T'HH:mm:ssZ||epoch_millis"
62-
}
63-
}
64-
},
65-
{
66-
"metadata_bools": {
67-
"path_match": "metadata.*",
68-
"match_mapping_type": "boolean",
69-
"mapping": {"type": "boolean"}
55+
"format": "strict_date_optional_time||strict_date_time||yyyy-MM-dd'T'HH:mm:ssZ||epoch_millis",
56+
},
7057
}
7158
},
59+
{"metadata_bools": {"path_match": "metadata.*", "match_mapping_type": "boolean", "mapping": {"type": "boolean"}}},
7260
{
7361
"metadata_numbers_long": {
7462
"path_match": "metadata.*",
7563
"match_mapping_type": "long",
76-
"mapping": {"type": "long", "ignore_malformed": True, "coerce": True}
64+
"mapping": {"type": "long", "ignore_malformed": True, "coerce": True},
7765
}
7866
},
7967
{
8068
"metadata_numbers_double": {
8169
"path_match": "metadata.*",
8270
"match_mapping_type": "double",
83-
"mapping": {"type": "double", "ignore_malformed": True, "coerce": True}
71+
"mapping": {"type": "double", "ignore_malformed": True, "coerce": True},
8472
}
8573
},
8674
{
8775
"metadata_strings": {
8876
"path_match": "metadata.*",
8977
"match_mapping_type": "string",
90-
"mapping": {"type": "keyword", "ignore_above": 1024}
78+
"mapping": {"type": "keyword", "ignore_above": 1024},
9179
}
92-
}
80+
},
9381
],
9482
"date_detection": False,
9583
"numeric_detection": False,

api/helpers/_accesscontroller.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic import BaseModel
99
from sqlalchemy.ext.asyncio import AsyncSession
1010

11-
from api.schemas.admin.roles import Limit, LimitType, PermissionType, Role
11+
from api.schemas.admin.roles import Limit, LimitType, PermissionType
1212
from api.schemas.admin.users import User
1313
from api.schemas.collections import CollectionVisibility
1414
from api.schemas.me import UserInfo
@@ -115,7 +115,6 @@ async def __call__(
115115
if request.url.path.endswith(ENDPOINT__ROUTERS) and request.method in ["GET"]:
116116
await self._check_provider(user_info=user_info, limits=limits, request=request)
117117

118-
await session.rollback()
119118
return user_info
120119

121120
def __get_user_limits(self, user_info: UserInfo) -> Dict[str, _UserModelLimits]:
@@ -144,7 +143,7 @@ def __get_user_limits(self, user_info: UserInfo) -> Dict[str, _UserModelLimits]:
144143

145144
async def _check_api_key(
146145
self, api_key: HTTPAuthorizationCredentials, session: AsyncSession
147-
) -> tuple[User, Role, Dict[str, _UserModelLimits], int | None]:
146+
) -> tuple[User, Dict[str, _UserModelLimits], int | None]:
148147
if api_key.scheme != "Bearer":
149148
raise InvalidAuthenticationSchemeException()
150149

api/helpers/_identityaccessmanager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ async def get_roles(
212212
role_id = row.role_id
213213
if role_id in roles:
214214
roles[role_id].limits.append(Limit(model=row.model, type=row.type, value=row.value))
215-
216215
# Query permissions for these roles
217216
permissions_query = select(PermissionTable.role_id, PermissionTable.permission).where(PermissionTable.role_id.in_(list(roles.keys())))
218217

@@ -221,7 +220,6 @@ async def get_roles(
221220
role_id = row.role_id
222221
if role_id in roles:
223222
roles[role_id].permissions.append(PermissionType(value=row.permission))
224-
225223
return list(roles.values())
226224

227225
async def create_user(
@@ -739,7 +737,7 @@ async def login(self, session: AsyncSession, email: str, password: str) -> Tuple
739737
if email == "master" and password == self.master_key:
740738
return 0, self.master_key
741739

742-
user = await self.get_user_info(session, email=email) # raise UserNotFoundException (404) if user not found
740+
user = await self.get_user_info(session=session, email=email) # raise UserNotFoundException (404) if user not found
743741
result = await session.execute(statement=select(UserTable.password).where(UserTable.id == user.id))
744742
user_password = result.scalar_one()
745743

api/sql/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ async def get_db_session():
3636
get_db_func = get_db_dependency()
3737
async for session in get_db_func():
3838
yield session
39+
if session.in_transaction():
40+
await session.close()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
"alembic==1.15.1",
1313
"psycopg2-binary==2.9.10",
1414
"asyncpg==0.30.0",
15-
"sqlalchemy[asyncio]==2.0.38",
15+
"sqlalchemy[asyncio]==2.0.43",
1616
"sqlalchemy-utils==0.41.2",
1717
"sentry-sdk[fastapi]>=2.28.0",
1818
"bcrypt==4.3.0"
@@ -47,7 +47,7 @@ api = [
4747

4848
# app
4949
"gunicorn==23.0.0",
50-
"fastapi==0.115.8",
50+
"fastapi==0.117.1",
5151
"prometheus-fastapi-instrumentator==7.0.2",
5252
"pyyaml==6.0.2",
5353
"uvicorn==0.34.0",

0 commit comments

Comments
 (0)