From 818dfa7c6dcf34c2b9d0c81f29c83c71c811f32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 19 Jun 2024 17:11:59 +0200 Subject: [PATCH 1/6] ci: skip test run_flow_from_json_object (#2227) ci: skip test test_run_flow_from_json_object --- tests/unit/conftest.py | 2 ++ tests/unit/test_loading.py | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 17ebc20e1..355cd5d2d 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -35,6 +35,8 @@ load_dotenv() def pytest_configure(config): config.addinivalue_line("markers", "noclient: don't create a client for this test") + config.addinivalue_line("markers", "load_flows: load the flows for this test") + config.addinivalue_line("markers", "api_key_required: run only if the api key is set in the environment variables") data_path = Path(__file__).parent.parent.absolute() / "data" pytest.BASIC_EXAMPLE_PATH = data_path / "basic_example.json" diff --git a/tests/unit/test_loading.py b/tests/unit/test_loading.py index 5872d060f..a3138f22c 100644 --- a/tests/unit/test_loading.py +++ b/tests/unit/test_loading.py @@ -33,6 +33,7 @@ def test_load_flow_from_json_object(): @pytest.mark.noclient +@pytest.mark.api_key_required def test_run_flow_from_json_object(): """Test loading a flow from a json file and applying tweaks""" _, projects = zip(*load_starter_projects()) From da6bfc2ec1960944532be8cf719c4d7e7ba4a7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 19 Jun 2024 17:15:23 +0200 Subject: [PATCH 2/6] fix: got unexpected 'lock' (#2228) --- src/backend/base/langflow/api/v1/chat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/base/langflow/api/v1/chat.py b/src/backend/base/langflow/api/v1/chat.py index df4aeb294..031772852 100644 --- a/src/backend/base/langflow/api/v1/chat.py +++ b/src/backend/base/langflow/api/v1/chat.py @@ -172,7 +172,6 @@ async def build_vertex( artifacts, vertex, ) = await graph.build_vertex( - lock=lock, chat_service=chat_service, vertex_id=vertex_id, user_id=current_user.id, From e45737aaaa91383756c976768af94539e46b0515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 19 Jun 2024 14:38:55 +0200 Subject: [PATCH 3/6] fix: graph process should raise the actual error when failing --- src/backend/base/langflow/graph/graph/base.py | 2 +- tests/unit/conftest.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index 569b1be4b..5e176ef81 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -836,7 +836,7 @@ class Graph: next_runnable_vertices = await self._execute_tasks(tasks, lock=lock) except Exception as e: logger.error(f"Error executing tasks in layer {layer_index}: {e}") - break + raise e if not next_runnable_vertices: break to_process.extend(next_runnable_vertices) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 355cd5d2d..e9c51180d 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -224,6 +224,7 @@ def json_vector_store(): @pytest.fixture(name="client", autouse=True) def client_fixture(session: Session, monkeypatch, request, load_flows_dir): + monkeypatch.setenv("LANGFLOW_LOG_LEVEL", "DEBUG") # Set the database url to a test database if "noclient" in request.keywords: yield From 51c1aa1ec807676f4db5a57cb34bd5f4ea4311ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 19 Jun 2024 14:39:13 +0200 Subject: [PATCH 4/6] fix: graph process should raise the actual error when failing --- tests/unit/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index e9c51180d..355cd5d2d 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -224,7 +224,6 @@ def json_vector_store(): @pytest.fixture(name="client", autouse=True) def client_fixture(session: Session, monkeypatch, request, load_flows_dir): - monkeypatch.setenv("LANGFLOW_LOG_LEVEL", "DEBUG") # Set the database url to a test database if "noclient" in request.keywords: yield From 5a412245605fd53d89329e1da9ac07aa35e9b268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 19 Jun 2024 14:09:20 +0200 Subject: [PATCH 5/6] fix: do not open browser on backend_only mode --- src/backend/base/langflow/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/base/langflow/__main__.py b/src/backend/base/langflow/__main__.py index 343188336..4234e892c 100644 --- a/src/backend/base/langflow/__main__.py +++ b/src/backend/base/langflow/__main__.py @@ -167,7 +167,7 @@ def run( else: # Run using gunicorn on Linux process = run_on_mac_or_linux(host, port, log_level, options, app) - if open_browser: + if open_browser and not backend_only: click.launch(f"http://{host}:{port}") if process: process.join() From e3656a6a43b79009fba95cd32ccfba0f9636039a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Wed, 19 Jun 2024 18:15:50 +0200 Subject: [PATCH 6/6] fix: "Flow" object has no field "last_tested_version" when loading flows from dir (#2221) --- src/backend/base/langflow/initial_setup/setup.py | 6 +++--- tests/data/basic_example.json | 5 +++-- tests/unit/test_database.py | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/backend/base/langflow/initial_setup/setup.py b/src/backend/base/langflow/initial_setup/setup.py index dc66b0371..8209a9d00 100644 --- a/src/backend/base/langflow/initial_setup/setup.py +++ b/src/backend/base/langflow/initial_setup/setup.py @@ -341,9 +341,9 @@ def load_flows_from_directory(): if existing: logger.info(f"Updating existing flow: {flow_id} with endpoint name {flow_endpoint_name}") for key, value in flow.items(): - if key == "last_tested_version": - continue - setattr(existing, key, value) + if hasattr(existing, key): + # flow dict from json and db representation are not 100% the same + setattr(existing, key, value) existing.updated_at = datetime.utcnow() existing.user_id = user_id session.add(existing) diff --git a/tests/data/basic_example.json b/tests/data/basic_example.json index 35f515bc4..e3a5141a6 100644 --- a/tests/data/basic_example.json +++ b/tests/data/basic_example.json @@ -505,5 +505,6 @@ "y": 0, "zoom": 0.5 } - } -} \ No newline at end of file + }, + "last_tested_version": "0.6.2" +} diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py index e689f558d..e09f9f62e 100644 --- a/tests/unit/test_database.py +++ b/tests/unit/test_database.py @@ -6,7 +6,7 @@ from fastapi.testclient import TestClient from sqlmodel import Session from langflow.api.v1.schemas import FlowListCreate -from langflow.initial_setup.setup import load_starter_projects +from langflow.initial_setup.setup import load_starter_projects, load_flows_from_directory from langflow.services.database.models.base import orjson_dumps from langflow.services.database.models.flow import Flow, FlowCreate, FlowUpdate from langflow.services.database.utils import session_getter @@ -271,7 +271,11 @@ def test_read_only_starter_projects(client: TestClient, active_user, logged_in_h @pytest.mark.load_flows def test_load_flows(client: TestClient, load_flows_dir): - client.get("/api/v1/auto_login") + response = client.get("api/v1/flows/c54f9130-f2fa-4a3e-b22a-3856d946351b") + assert response.status_code == 200 + assert response.json()["name"] == "BasicExample" + # re-run to ensure updates work well + load_flows_from_directory() response = client.get("api/v1/flows/c54f9130-f2fa-4a3e-b22a-3856d946351b") assert response.status_code == 200 assert response.json()["name"] == "BasicExample"