ref: Remove unused sync session_scope, with_session and engine (#5333)

Remove unused sync session_scope, with_session and engine
This commit is contained in:
Christophe Bornet 2024-12-18 21:52:06 +01:00 • committed by GitHub
commit 3f0e383135
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 75 additions and 114 deletions

View file

@ -400,7 +400,7 @@ async def test_user(client):
@pytest.fixture
async def active_user(client): # noqa: ARG001
db_manager = get_db_service()
async with db_manager.with_async_session() as session:
async with db_manager.with_session() as session:
user = User(
username="activeuser",
password=get_password_hash("testpassword"),
@ -418,7 +418,7 @@ async def active_user(client): # noqa: ARG001
yield user
# Clean up
# Now cleanup transactions, vertex_build
async with db_manager.with_async_session() as session:
async with db_manager.with_session() as session:
user = await session.get(User, user.id, options=[selectinload(User.flows)])
await _delete_transactions_and_vertex_builds(session, user.flows)
await session.delete(user)
@ -439,7 +439,7 @@ async def logged_in_headers(client, active_user):
@pytest.fixture
async def active_super_user(client): # noqa: ARG001
db_manager = get_db_service()
async with db_manager.with_async_session() as session:
async with db_manager.with_session() as session:
user = User(
username="activeuser",
password=get_password_hash("testpassword"),
@ -457,7 +457,7 @@ async def active_super_user(client): # noqa: ARG001
yield user
# Clean up
# Now cleanup transactions, vertex_build
async with db_manager.with_async_session() as session:
async with db_manager.with_session() as session:
user = await session.get(User, user.id, options=[selectinload(User.flows)])
await _delete_transactions_and_vertex_builds(session, user.flows)
await session.delete(user)

View file

@ -615,14 +615,14 @@ async def test_read_only_starter_projects(client: AsyncClient, logged_in_headers
assert len(response.json()) == len(starter_projects)
def test_sqlite_pragmas():
async def test_sqlite_pragmas():
db_service = get_db_service()
with db_service.with_session() as session:
async with db_service.with_session() as session:
from sqlalchemy import text
assert session.exec(text("PRAGMA journal_mode;")).scalar() == "wal"
assert session.exec(text("PRAGMA synchronous;")).scalar() == 1
assert (await session.exec(text("PRAGMA journal_mode;"))).scalar() == "wal"
assert (await session.exec(text("PRAGMA synchronous;"))).scalar() == 1
@pytest.mark.usefixtures("active_user")

View file

@ -11,7 +11,7 @@ from langflow.initial_setup.setup import (
)
from langflow.interface.types import aget_all_types_dict
from langflow.services.database.models.folder.model import Folder
from langflow.services.deps import async_session_scope
from langflow.services.deps import session_scope
from sqlalchemy.orm import selectinload
from sqlmodel import select
@ -52,7 +52,7 @@ async def test_get_project_data():
@pytest.mark.usefixtures("client")
async def test_create_or_update_starter_projects():
async with async_session_scope() as session:
async with session_scope() as session:
# Get the number of projects returned by load_starter_projects
num_projects = len(await load_starter_projects())

View file

@ -1,7 +1,7 @@
import pytest
from langflow.services.auth.utils import get_password_hash
from langflow.services.database.models.user import User
from langflow.services.deps import async_session_scope
from langflow.services.deps import session_scope
from sqlalchemy.exc import IntegrityError
@ -18,7 +18,7 @@ def test_user():
async def test_login_successful(client, test_user):
# Adding the test user to the database
try:
async with async_session_scope() as session:
async with session_scope() as session:
session.add(test_user)
await session.commit()
except IntegrityError:

View file

@ -22,13 +22,13 @@ from langflow.schema.properties import Properties, Source
# Assuming you have these imports available
from langflow.services.database.models.message import MessageCreate, MessageRead
from langflow.services.database.models.message.model import MessageTable
from langflow.services.deps import async_session_scope
from langflow.services.deps import session_scope
from langflow.services.tracing.utils import convert_to_langchain_type
@pytest.fixture
async def created_message():
async with async_session_scope() as session:
async with session_scope() as session:
message = MessageCreate(text="Test message", sender="User", sender_name="User", session_id="session_id")
messagetable = MessageTable.model_validate(message, from_attributes=True)
messagetables = await aadd_messagetables([messagetable], session)
@ -37,7 +37,7 @@ async def created_message():
@pytest.fixture
async def created_messages(async_session): # noqa: ARG001
async with async_session_scope() as _session:
async with session_scope() as _session:
messages = [
MessageCreate(text="Test message 1", sender="User", sender_name="User", session_id="session_id2"),
MessageCreate(text="Test message 2", sender="User", sender_name="User", session_id="session_id2"),

View file

@ -8,12 +8,12 @@ from langflow.memory import aadd_messagetables
# Assuming you have these imports available
from langflow.services.database.models.message import MessageCreate, MessageRead, MessageUpdate
from langflow.services.database.models.message.model import MessageTable
from langflow.services.deps import async_session_scope
from langflow.services.deps import session_scope
@pytest.fixture
async def created_message():
async with async_session_scope() as session:
async with session_scope() as session:
message = MessageCreate(text="Test message", sender="User", sender_name="User", session_id="session_id")
messagetable = MessageTable.model_validate(message, from_attributes=True)
messagetables = await aadd_messagetables([messagetable], session)
@ -22,7 +22,7 @@ async def created_message():
@pytest.fixture
async def created_messages(session): # noqa: ARG001
async with async_session_scope() as _session:
async with session_scope() as _session:
messages = [
MessageCreate(text="Test message 1", sender="User", sender_name="User", session_id="session_id2"),
MessageCreate(text="Test message 2", sender="User", sender_name="User", session_id="session_id2"),