feat: clean messages table after run in flow_runner (#8773)

* feat: flow_runner cleanup messages table

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* fix lint

* lint

* fix lint

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Bar Nuri 2025-07-01 14:49:03 +03:00 • committed by GitHub
commit 087fa34a57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 44 deletions

View file

@ -2701,8 +2701,6 @@
"group_outputs": false,
"method": "search_documents",
"name": "search_results",
"options": null,
"required_inputs": null,
"selected": "Data",
"tool_mode": true,
"types": [
@ -2717,8 +2715,6 @@
"group_outputs": false,
"method": "as_dataframe",
"name": "dataframe",
"options": null,
"required_inputs": null,
"selected": "DataFrame",
"tool_mode": true,
"types": [
@ -2734,8 +2730,6 @@
"hidden": true,
"method": "as_vector_store",
"name": "vectorstoreconnection",
"options": null,
"required_inputs": null,
"selected": "VectorStore",
"tool_mode": true,
"types": [
@ -3071,9 +3065,7 @@
"dynamic": false,
"info": "The Database name for the Astra DB instance.",
"name": "database_name",
"options": [
"us-east-2"
],
"options": [],
"options_metadata": [
{
"api_endpoint": "https://5b8bb22c-4a38-4f0a-865c-a18ed7590bd1-us-east-2.apps.astra.datastax.com",
@ -3482,8 +3474,6 @@
"group_outputs": false,
"method": "search_documents",
"name": "search_results",
"options": null,
"required_inputs": null,
"selected": "Data",
"tool_mode": true,
"types": [
@ -3498,8 +3488,6 @@
"group_outputs": false,
"method": "as_dataframe",
"name": "dataframe",
"options": null,
"required_inputs": null,
"selected": "DataFrame",
"tool_mode": true,
"types": [
@ -3515,8 +3503,6 @@
"hidden": true,
"method": "as_vector_store",
"name": "vectorstoreconnection",
"options": null,
"required_inputs": null,
"selected": "VectorStore",
"tool_mode": true,
"types": [
@ -3851,9 +3837,7 @@
"dynamic": false,
"info": "The Database name for the Astra DB instance.",
"name": "database_name",
"options": [
"us-east-2"
],
"options": [],
"options_metadata": [
{
"api_endpoint": "https://5b8bb22c-4a38-4f0a-865c-a18ed7590bd1-us-east-2.apps.astra.datastax.com",

View file

@ -5,7 +5,7 @@ from uuid import UUID, uuid4
from aiofile import async_open
from loguru import logger
from sqlmodel import delete, text
from sqlmodel import delete, select, text
from langflow.api.utils import cascade_delete_flow
from langflow.graph import Graph
@ -17,9 +17,7 @@ from langflow.services.auth.utils import (
get_password_hash,
)
from langflow.services.cache.service import AsyncBaseCacheService
from langflow.services.database.models.flow import Flow
from langflow.services.database.models.user import User
from langflow.services.database.models.variable import Variable
from langflow.services.database.models import Flow, User, Variable
from langflow.services.database.utils import initialize_database
from langflow.services.deps import get_cache_service, get_storage_service, session_scope
from langflow.utils.util import update_settings
@ -228,9 +226,12 @@ class LangflowRunnerExperimental:
@staticmethod
async def clear_user_state(user_id: str):
async with session_scope() as session:
await session.exec(delete(Flow).where(Flow.user_id == user_id))
await session.exec(delete(User).where(User.id == user_id))
flows = await session.exec(select(Flow.id).where(Flow.user_id == user_id))
flow_ids: list[UUID] = [fid for fid in flows.scalars().all() if fid is not None]
for flow_id in flow_ids:
await cascade_delete_flow(session, flow_id)
await session.exec(delete(Variable).where(Variable.user_id == user_id))
await session.exec(delete(User).where(User.id == user_id))
async def init_db_if_needed(self):
if not await self.database_exists_check() and self.should_initialize_db: