Skip to content

fix: actually populate logs#10398

Closed
TejasQ wants to merge 2 commits into
langflow-ai:mainfrom
TejasQ:fix-logs
Closed

fix: actually populate logs#10398
TejasQ wants to merge 2 commits into
langflow-ai:mainfrom
TejasQ:fix-logs

Conversation

@TejasQ
Copy link
Copy Markdown
Contributor

@TejasQ TejasQ commented Oct 24, 2025

Not sure why, but logs are never populated. After looking into it, I found out it's because the log_transaction function in the LFX codebase was only a stub implementation that logged to the debug logger but never actually saved transactions to the database. This PR fixes this.

Current State

Screen.Recording.2025-10-24.at.17.53.19.mov

This PR

Screen.Recording.2025-10-24.at.17.54.28.mov

Summary by CodeRabbit

  • Enhancements
    • Transaction logging now attempts to persist vertex transaction data (including inputs, outputs, status, and errors) to the database when available, with automatic fallback to debug-level logging if database integration is unavailable or encounters issues.
    • Minor code cleanup for maintainability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 24, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The log_transaction function in utils.py is enhanced to persist transactions to a langflow database when available, with graceful fallback to debug-only logging. Inline noqa markers are removed from function parameters.

Changes

Cohort / File(s) Summary
Database logging enhancement
src/lfx/src/lfx/graph/utils.py
Added conditional database persistence attempt using langflow transaction models and CRUD operations; constructs TransactionBase with vertex_id, target_id, serialized inputs/outputs, status, error, and flow_id. Includes fallback to debug logging on ImportError or other exceptions during database operations. Removed inline noqa markers from target and error parameters. Updated docstring to document new behavior.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant log_transaction
    participant ImportAttempt as Import<br/>Langflow Models
    participant DB as Database<br/>Session
    participant Logger

    Caller->>log_transaction: call with transaction data
    log_transaction->>ImportAttempt: try import transaction models
    
    alt ImportError
        ImportAttempt-->>log_transaction: ImportError
        log_transaction->>Logger: debug log (fallback)
    else Import Success
        ImportAttempt-->>log_transaction: models available
        log_transaction->>log_transaction: construct TransactionBase
        log_transaction->>DB: persist transaction
        
        alt DB Success
            DB-->>log_transaction: success
            log_transaction->>Logger: log success message
        else DB Error
            DB-->>log_transaction: exception
            log_transaction->>Logger: log error + debug log
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 2 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The PR modifies only src/lfx/src/lfx/graph/utils.py to fix the bug where logs are not being populated, but contains zero test file changes. While existing test files like ./src/backend/tests/unit/test_database.py and ./src/lfx/tests/unit/graph/graph/test_utils.py exist that test related functionality, this PR does not include any new tests or modifications to existing tests to verify the bug fix works correctly or to prevent regressions. The git history confirms only the implementation file was changed, with no test additions. Add regression tests to this PR that verify the bug fix works as intended. Tests should cover successful database transaction logging when available, fallback behavior when database imports fail, and proper error handling during database operations. These tests should be added to existing test files following the project's conventions, such as ./src/lfx/tests/unit/graph/graph/test_utils.py for unit tests of the utility functions or ./src/backend/tests/unit/test_database.py for integration tests of the logging functionality.
Test Quality And Coverage ⚠️ Warning The PR modifies log_transaction in src/lfx/src/lfx/graph/utils.py to add database logging with fallback to debug logging, but introduces no new dedicated unit tests for this functionality. While integration tests exist in src/backend/tests/unit/test_database.py (such as test_delete_flows_with_transaction_and_build), these are end-to-end tests that verify flow deletion works and transactions are cleaned up, but do not isolate or validate the new logging implementation details. These integration tests do not test: successful database transaction persistence with proper vertex serialization, the ImportError fallback mechanism, exception handling during database operations, or correct parameter transformation. The new functionality requires comprehensive unit tests using pytest's @pytest.mark.asyncio decorator with mocked dependencies to validate all code paths before integration testing. Add a new dedicated unit test file src/backend/tests/unit/test_log_transaction.py with @pytest.mark.asyncio decorated async test functions using unittest.mock to isolate and validate: (1) successful database transaction logging when all imports and services are available, verifying the correct TransactionBase data structure is created and passed to db_log_transaction; (2) ImportError fallback when langflow transaction models are unavailable; (3) exception handling when database operations fail, ensuring the function logs the error and continues gracefully; (4) proper serialization of vertex parameters through _vertex_to_primitive_dict for both inputs and outputs; and (5) edge cases such as None targets, missing flow_ids, and disabled transaction storage settings. These tests should follow the project's existing pytest patterns and mock external dependencies to ensure comprehensive coverage of the new code paths.
Test File Naming And Structure ⚠️ Warning The PR modifies src/lfx/src/lfx/graph/utils.py at the graph module root level, but there is no corresponding test file src/lfx/tests/unit/graph/test_utils.py. The repository demonstrates a clear pattern of mirrored test structure—test files exist for other graph modules including src/lfx/tests/unit/graph/graph/test_utils.py for graph-specific utilities, src/lfx/tests/unit/graph/test_graph.py, and edge/vertex test files. The PR introduces significant new functionality with database logging and multiple exception handling paths (ImportError, database exceptions) but contains only source code changes with zero test file additions or modifications. This violates the established testing structure and naming conventions. Create a new test file at src/lfx/tests/unit/graph/test_utils.py following the repository's test_*.py naming convention. Include comprehensive test functions with descriptive names covering: successful database transaction persistence, ImportError fallback to debug logging, database exception handling without failing the transaction, inputs serialization from source vertex params, outputs handling when target is present or None, status and error serialization, and edge cases with missing vertex attributes. Use pytest fixtures for mocking database sessions, langflow models, and transaction CRUD operations. Organize tests with proper setup/teardown to ensure both positive and negative scenarios validate the enhanced log_transaction behavior.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: actually populate logs" directly addresses the PR's primary objective of fixing the issue where logs are never populated. The changes implement actual database logging functionality by adding a dynamic logging path that attempts langflow database logging with appropriate fallbacks, whereas previously only debug logging was performed. The title is concise, specific, and clearly conveys the main fix to a teammate reviewing the change history, accurately reflecting that this PR adds real logging functionality that was missing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Excessive Mock Usage Warning ✅ Passed This PR (#10398) modifies only the implementation file src/lfx/src/lfx/graph/utils.py without adding, modifying, or removing any test files. The custom check "Excessive Mock Usage Warning" is designed to evaluate test files for poor mock usage patterns, but no tests were added or modified in this PR. The existing test infrastructure in src/lfx/tests/unit/graph/graph/test_utils.py and src/lfx/tests/conftest.py demonstrates appropriate mocking practices: the use_noop_session fixture appropriately mocks the session_scope external dependency rather than core logic, which aligns with best practices. Since the check cannot be applied to tests that don't exist in this PR's scope, and the existing test patterns show correct usage of mocks for external dependencies, the check passes by default.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Oct 24, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Oct 24, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
src/lfx/src/lfx/graph/utils.py (2)

112-114: Tighten parameter types for clarity and safety.

Annotate status and error explicitly; keeps TransactionBase.status consistent and clarifies accepted error types.

-async def log_transaction(
-    flow_id: str | UUID,
-    source: Vertex,
-    status,
-    target: Vertex | None = None,
-    error=None,
-) -> None:
+async def log_transaction(
+    flow_id: str | UUID,
+    source: Vertex,
+    status: str,
+    target: Vertex | None = None,
+    error: Exception | str | None = None,
+) -> None:

121-129: Debug logging suggestion for disabled transaction storage is valid.

The flag name transactions_storage_enabled is correctly defined in the settings model and used throughout the codebase. The suggested debug log is a reasonable optional improvement that aligns with existing debug logging patterns in the same function (e.g., the db_service is None check on line 128). The developer can implement this at their discretion.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d707176 and e497c6b.

📒 Files selected for processing (1)
  • src/lfx/src/lfx/graph/utils.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/lfx/src/lfx/graph/utils.py (2)
src/backend/base/langflow/services/database/models/transactions/model.py (1)
  • TransactionBase (10-55)
src/backend/base/langflow/services/deps.py (1)
  • session_scope (162-184)
🪛 GitHub Actions: Ruff Style Check
src/lfx/src/lfx/graph/utils.py

[error] 138-138: Ruff: Import block is unsorted or unformatted (I001). Command 'uv run --only-dev ruff check --output-format=github .' reported the issue.

🪛 GitHub Check: Ruff Style Check (3.13)
src/lfx/src/lfx/graph/utils.py

[failure] 166-166: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:166:1: W293 Blank line contains whitespace


[failure] 162-162: Ruff (BLE001)
src/lfx/src/lfx/graph/utils.py:162:16: BLE001 Do not catch blind exception: Exception


[failure] 158-158: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:158:1: W293 Blank line contains whitespace


[failure] 156-156: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:156:1: W293 Blank line contains whitespace


[failure] 152-152: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:152:1: W293 Blank line contains whitespace


[failure] 147-147: Ruff (Q000)
src/lfx/src/lfx/graph/utils.py:147:89: Q000 Single quotes found but double quotes preferred


[failure] 146-146: Ruff (Q000)
src/lfx/src/lfx/graph/utils.py:146:77: Q000 Single quotes found but double quotes preferred


[failure] 141-141: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:141:1: W293 Blank line contains whitespace


[failure] 138-140: Ruff (I001)
src/lfx/src/lfx/graph/utils.py:138:13: I001 Import block is un-sorted or un-formatted

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Update Component Index
  • GitHub Check: Update Starter Projects
🔇 Additional comments (2)
src/lfx/src/lfx/graph/utils.py (2)

117-119: Docstring update reads well.

Accurately reflects the new DB‑backed logging with graceful fallback.


154-156: DB logging path LGTM.

Async session usage + single write via db_log_transaction is appropriate.

Comment thread src/lfx/src/lfx/graph/utils.py Outdated
Comment on lines +136 to +141
# Try to use the full langflow transaction logging implementation
try:
from langflow.services.database.models.transactions.model import TransactionBase
from langflow.services.database.models.transactions.crud import log_transaction as db_log_transaction
from langflow.services.deps import session_scope

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Fix import order to satisfy Ruff (I001).

Sort the inner import block alphabetically by module path.

-            from langflow.services.database.models.transactions.model import TransactionBase
-            from langflow.services.database.models.transactions.crud import log_transaction as db_log_transaction
-            from langflow.services.deps import session_scope
+            from langflow.services.database.models.transactions.crud import log_transaction as db_log_transaction
+            from langflow.services.database.models.transactions.model import TransactionBase
+            from langflow.services.deps import session_scope
🧰 Tools
🪛 GitHub Actions: Ruff Style Check

[error] 138-138: Ruff: Import block is unsorted or unformatted (I001). Command 'uv run --only-dev ruff check --output-format=github .' reported the issue.

🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 141-141: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:141:1: W293 Blank line contains whitespace


[failure] 138-140: Ruff (I001)
src/lfx/src/lfx/graph/utils.py:138:13: I001 Import block is un-sorted or un-formatted

🤖 Prompt for AI Agents
In src/lfx/src/lfx/graph/utils.py around lines 136 to 141, the inner try-import
block is not alphabetically ordered causing Ruff I001; reorder the three imports
alphabetically by their full module path so the import lines read in ascending
lexical order (i.e., ensure the module paths are sorted) and preserve them
inside the try block exactly as before.

Comment thread src/lfx/src/lfx/graph/utils.py Outdated
from langflow.services.database.models.transactions.model import TransactionBase
from langflow.services.database.models.transactions.crud import log_transaction as db_log_transaction
from langflow.services.deps import session_scope

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Strip trailing whitespace on blank lines (W293).

Ruff flags these blanks as containing whitespace. Remove trailing spaces to pass style checks.

Also applies to: 152-152, 156-156, 158-158, 166-166

🧰 Tools
🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 141-141: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:141:1: W293 Blank line contains whitespace

🤖 Prompt for AI Agents
In src/lfx/src/lfx/graph/utils.py around lines 141, 152, 156, 158, and 166,
several blank lines contain trailing whitespace (Ruff W293); remove any trailing
spaces on those blank lines so they are truly empty (no spaces or tabs), re-save
the file, and re-run the linter to confirm W293 is resolved.

Comment on lines +143 to +151
transaction_data = TransactionBase(
vertex_id=source.id,
target_id=target.id if target else None,
inputs=_vertex_to_primitive_dict(source) if hasattr(source, 'data') else None,
outputs=_vertex_to_primitive_dict(target) if target and hasattr(target, 'data') else None,
status=status,
error=str(error) if error else None,
flow_id=flow_id,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: inputs/outputs guards check .data but serializer reads .params.

_vertex_to_primitive_dict accesses vertex.params. Using hasattr(..., "data") will often return False, causing inputs/outputs to be None and logs to remain empty.

-            transaction_data = TransactionBase(
-                vertex_id=source.id,
-                target_id=target.id if target else None,
-                inputs=_vertex_to_primitive_dict(source) if hasattr(source, 'data') else None,
-                outputs=_vertex_to_primitive_dict(target) if target and hasattr(target, 'data') else None,
-                status=status,
-                error=str(error) if error else None,
-                flow_id=flow_id,
-            )
+            transaction_data = TransactionBase(
+                vertex_id=source.id,
+                target_id=target.id if target else None,
+                inputs=_vertex_to_primitive_dict(source),
+                outputs=_vertex_to_primitive_dict(target) if target else None,
+                status=str(status),
+                error=str(error) if error is not None else None,
+                flow_id=flow_id,
+            )

Also addresses Q000 by using double quotes in the modified lines.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
transaction_data = TransactionBase(
vertex_id=source.id,
target_id=target.id if target else None,
inputs=_vertex_to_primitive_dict(source) if hasattr(source, 'data') else None,
outputs=_vertex_to_primitive_dict(target) if target and hasattr(target, 'data') else None,
status=status,
error=str(error) if error else None,
flow_id=flow_id,
)
transaction_data = TransactionBase(
vertex_id=source.id,
target_id=target.id if target else None,
inputs=_vertex_to_primitive_dict(source),
outputs=_vertex_to_primitive_dict(target) if target else None,
status=str(status),
error=str(error) if error is not None else None,
flow_id=flow_id,
)
🧰 Tools
🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 147-147: Ruff (Q000)
src/lfx/src/lfx/graph/utils.py:147:89: Q000 Single quotes found but double quotes preferred


[failure] 146-146: Ruff (Q000)
src/lfx/src/lfx/graph/utils.py:146:77: Q000 Single quotes found but double quotes preferred

🤖 Prompt for AI Agents
In src/lfx/src/lfx/graph/utils.py around lines 143 to 151, the guard checks use
hasattr(vertex, 'data') but _vertex_to_primitive_dict reads vertex.params,
causing inputs/outputs to be None; update the conditional guards to check for
"params" (e.g., hasattr(source, "params") and hasattr(target, "params")) so the
serializer is invoked when params exist, and use double-quoted strings in the
modified lines.

Comment thread src/lfx/src/lfx/graph/utils.py Outdated
Comment on lines +160 to +166
# Fallback to debug logging if langflow models are not available
logger.debug(f"Transaction logged (debug only): vertex={source.id}, flow={flow_id}, status={status}")
except Exception as db_exc:
# Log database errors but don't fail the transaction
logger.debug(f"Error logging transaction to database: {db_exc!s}")
logger.debug(f"Transaction logged (debug only): vertex={source.id}, flow={flow_id}, status={status}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Ruff BLE001 and better diagnostics for DB logging failures.

Either narrow the exception types or mirror the outer pattern and suppress BLE001 here. Minimal change below also keeps CI green.

-        except ImportError:
+        except ImportError:
             # Fallback to debug logging if langflow models are not available
             logger.debug(f"Transaction logged (debug only): vertex={source.id}, flow={flow_id}, status={status}")
-        except Exception as db_exc:
+        except Exception as db_exc:  # noqa: BLE001
             # Log database errors but don't fail the transaction
-            logger.debug(f"Error logging transaction to database: {db_exc!s}")
+            logger.debug(f"Error logging transaction to database: {db_exc!s}")
             logger.debug(f"Transaction logged (debug only): vertex={source.id}, flow={flow_id}, status={status}")

Optional (recommended later): catch (ValueError, sqlalchemy.exc.SQLAlchemyError, pydantic.ValidationError) explicitly if those are guaranteed to be present.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 166-166: Ruff (W293)
src/lfx/src/lfx/graph/utils.py:166:1: W293 Blank line contains whitespace


[failure] 162-162: Ruff (BLE001)
src/lfx/src/lfx/graph/utils.py:162:16: BLE001 Do not catch blind exception: Exception

🤖 Prompt for AI Agents
In src/lfx/src/lfx/graph/utils.py around lines 160 to 166, change the bare
"except Exception" used for DB logging to a narrower explicit exception tuple
(e.g., except (ValueError, sqlalchemy.exc.SQLAlchemyError,
pydantic.ValidationError):) and add the necessary imports for sqlalchemy.exc and
pydantic.ValidationError at the top of the file; if any of those packages are
not available in this module's scope, alternatively keep Exception but append a
noqa comment to suppress BLE001 (e.g., # noqa: BLE001) and ensure the debug
messages remain the same so CI stays green.

Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @TejasQ

Thanks for noticing this!

The implementation has to similar to what we did on #10136

lfx can't import things from langflow because langflow depends on lfx.
Until we have a proper plugin system (#10111) we are patching the functions at import time.

@TejasQ
Copy link
Copy Markdown
Contributor Author

TejasQ commented Nov 6, 2025

Thanks, @ogabrielluiz! Does #10136 fix this issue to still show logs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants