ref: Make some functions that don't await non-async (RUF029) (#4368)
Make some functions that don't await non-async (RUF029)
This commit is contained in:
parent
35e2487acb
commit
10e1352ac4
12 changed files with 26 additions and 25 deletions
|
|
@ -98,7 +98,7 @@ def get_is_component_from_data(data: dict):
|
|||
return data.get("is_component")
|
||||
|
||||
|
||||
async def check_langflow_version(component: StoreComponentCreate) -> None:
|
||||
def check_langflow_version(component: StoreComponentCreate) -> None:
|
||||
from langflow.utils.version import get_version_info
|
||||
|
||||
__version__ = get_version_info()["version"]
|
||||
|
|
@ -264,7 +264,7 @@ def parse_value(value: Any, input_type: str) -> Any:
|
|||
return value
|
||||
|
||||
|
||||
async def cascade_delete_flow(session: Session, flow: Flow) -> None:
|
||||
def cascade_delete_flow(session: Session, flow: Flow) -> None:
|
||||
try:
|
||||
session.exec(delete(TransactionTable).where(TransactionTable.flow_id == flow.id))
|
||||
session.exec(delete(VertexBuildTable).where(VertexBuildTable.flow_id == flow.id))
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ async def update_flow(
|
|||
|
||||
|
||||
@router.delete("/{flow_id}", status_code=200)
|
||||
async def delete_flow(
|
||||
def delete_flow(
|
||||
*,
|
||||
session: DbSession,
|
||||
flow_id: UUID,
|
||||
|
|
@ -314,7 +314,7 @@ async def delete_flow(
|
|||
)
|
||||
if not flow:
|
||||
raise HTTPException(status_code=404, detail="Flow not found")
|
||||
await cascade_delete_flow(session, flow)
|
||||
cascade_delete_flow(session, flow)
|
||||
session.commit()
|
||||
return {"message": "Flow deleted successfully"}
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ async def update_folder(
|
|||
|
||||
|
||||
@router.delete("/{folder_id}", status_code=204)
|
||||
async def delete_folder(
|
||||
def delete_folder(
|
||||
*,
|
||||
session: DbSession,
|
||||
folder_id: str,
|
||||
|
|
@ -216,7 +216,7 @@ async def delete_folder(
|
|||
flows = session.exec(select(Flow).where(Flow.folder_id == folder_id, Flow.user_id == current_user.id)).all()
|
||||
if len(flows) > 0:
|
||||
for flow in flows:
|
||||
await cascade_delete_flow(session, flow)
|
||||
cascade_delete_flow(session, flow)
|
||||
|
||||
folder = session.exec(select(Folder).where(Folder.id == folder_id, Folder.user_id == current_user.id)).first()
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import asyncio
|
||||
from typing import Annotated
|
||||
from uuid import UUID
|
||||
|
||||
|
|
@ -67,7 +68,7 @@ async def share_component(
|
|||
store_api_key: Annotated[str, Depends(get_user_store_api_key)],
|
||||
) -> CreateComponentResponse:
|
||||
try:
|
||||
await check_langflow_version(component)
|
||||
await asyncio.to_thread(check_langflow_version, component)
|
||||
return await get_store_service().upload(store_api_key, component)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
|
@ -80,7 +81,7 @@ async def update_shared_component(
|
|||
store_api_key: Annotated[str, Depends(get_user_store_api_key)],
|
||||
) -> CreateComponentResponse:
|
||||
try:
|
||||
await check_langflow_version(component)
|
||||
await asyncio.to_thread(check_langflow_version, component)
|
||||
return await get_store_service().update(store_api_key, component_id, component)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ from langflow.logging.logger import LogConfig, configure
|
|||
from langflow.schema.schema import INPUT_FIELD_NAME, InputType
|
||||
from langflow.services.cache.utils import CacheMiss
|
||||
from langflow.services.deps import get_chat_service, get_tracing_service
|
||||
from langflow.utils.async_helpers import run_until_complete
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from langflow.api.v1.schemas import InputValueRequest
|
||||
|
|
@ -1126,7 +1125,7 @@ class Graph:
|
|||
# This is a hack to make sure that the LLM vertex is sent to
|
||||
# the toolkit vertex
|
||||
self._build_vertex_params()
|
||||
run_until_complete(self._instantiate_components_in_vertices())
|
||||
self._instantiate_components_in_vertices()
|
||||
self._set_cache_to_vertices_in_cycle()
|
||||
|
||||
def _get_edges_as_list_of_tuples(self) -> list[tuple[str, str]]:
|
||||
|
|
@ -1141,10 +1140,10 @@ class Graph:
|
|||
if vertex.id in cycle_vertices:
|
||||
vertex.apply_on_outputs(lambda output_object: setattr(output_object, "cache", False))
|
||||
|
||||
async def _instantiate_components_in_vertices(self) -> None:
|
||||
def _instantiate_components_in_vertices(self) -> None:
|
||||
"""Instantiates the components in the vertices."""
|
||||
for vertex in self.vertices:
|
||||
await vertex.instantiate_component(self.user_id)
|
||||
vertex.instantiate_component(self.user_id)
|
||||
|
||||
def remove_vertex(self, vertex_id: str) -> None:
|
||||
"""Removes a vertex from the graph."""
|
||||
|
|
|
|||
|
|
@ -462,9 +462,9 @@ class Vertex:
|
|||
self.params = self.raw_params.copy()
|
||||
self.updated_raw_params = True
|
||||
|
||||
async def instantiate_component(self, user_id=None) -> None:
|
||||
def instantiate_component(self, user_id=None) -> None:
|
||||
if not self.custom_component:
|
||||
self.custom_component, _ = await initialize.loading.instantiate_class(
|
||||
self.custom_component, _ = initialize.loading.instantiate_class(
|
||||
user_id=user_id,
|
||||
vertex=self,
|
||||
)
|
||||
|
|
@ -484,7 +484,7 @@ class Vertex:
|
|||
raise ValueError(msg)
|
||||
|
||||
if not self.custom_component:
|
||||
custom_component, custom_params = await initialize.loading.instantiate_class(
|
||||
custom_component, custom_params = initialize.loading.instantiate_class(
|
||||
user_id=user_id, vertex=self, event_manager=event_manager
|
||||
)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ if TYPE_CHECKING:
|
|||
from langflow.graph.vertex.base import Vertex
|
||||
|
||||
|
||||
async def instantiate_class(
|
||||
def instantiate_class(
|
||||
vertex: Vertex,
|
||||
user_id=None,
|
||||
event_manager: EventManager | None = None,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import asyncio
|
||||
import base64
|
||||
import random
|
||||
import warnings
|
||||
|
|
@ -32,7 +33,7 @@ MINIMUM_KEY_LENGTH = 32
|
|||
|
||||
|
||||
# Source: https://github.com/mrtolkien/fastapi_simple_security/blob/master/fastapi_simple_security/security_api_key.py
|
||||
async def api_key_security(
|
||||
def api_key_security(
|
||||
query_param: Annotated[str, Security(api_key_query)],
|
||||
header_param: Annotated[str, Security(api_key_header)],
|
||||
db: Annotated[Session, Depends(get_session)],
|
||||
|
|
@ -82,7 +83,7 @@ async def get_current_user(
|
|||
) -> User:
|
||||
if token:
|
||||
return await get_current_user_by_jwt(token, db)
|
||||
user = await api_key_security(query_param, header_param, db)
|
||||
user = await asyncio.to_thread(api_key_security, query_param, header_param, db)
|
||||
if user:
|
||||
return user
|
||||
|
||||
|
|
@ -163,7 +164,7 @@ async def get_current_user_for_websocket(
|
|||
if token:
|
||||
return await get_current_user_by_jwt(token, db)
|
||||
if api_key:
|
||||
return await api_key_security(api_key, query_param, db)
|
||||
return await asyncio.to_thread(api_key_security, api_key, query_param, db)
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ def _wrap_file_read_blocking(func):
|
|||
for frame_info in inspect.stack():
|
||||
if isinstance(frame_info.frame.f_locals.get("self"), FileLoader):
|
||||
return func(self, *args, **kwargs)
|
||||
if frame_info.filename.endswith("_pytest/assertion/rewrite.py") and frame_info.function in [
|
||||
if frame_info.filename.endswith("_pytest/assertion/rewrite.py") and frame_info.function in {
|
||||
"_rewrite_test",
|
||||
"_read_pyc",
|
||||
]:
|
||||
}:
|
||||
return func(self, *args, **kwargs)
|
||||
raise _blocking_error(func)
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ def _wrap_file_write_blocking(func):
|
|||
for frame_info in inspect.stack():
|
||||
if frame_info.filename.endswith("_pytest/assertion/rewrite.py") and frame_info.function == "_write_pyc":
|
||||
return func(self, *args, **kwargs)
|
||||
if self not in [sys.stdout, sys.stderr]:
|
||||
if self not in {sys.stdout, sys.stderr}:
|
||||
raise _blocking_error(func)
|
||||
return func(self, *args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from httpx import AsyncClient
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def body():
|
||||
def body():
|
||||
return {
|
||||
"name": "test_variable",
|
||||
"value": "test_value",
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from langflow.services.deps import session_scope
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
async def created_message():
|
||||
def created_message():
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ async def test_inactive_user(client: AsyncClient):
|
|||
|
||||
|
||||
@pytest.mark.api_key_required
|
||||
async def test_add_user(test_user):
|
||||
def test_add_user(test_user):
|
||||
assert test_user["username"] == "testuser"
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue