-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat: remove code from Transactions to reduce clutter in logs
#10400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8976024
refactor: remove code from transaction model inputs
ogabrielluiz 43074b0
refactor: remove code from transaction model inputs
ogabrielluiz 6825309
tests: add tests to make sure code is not added to transactions data
ogabrielluiz 5cff712
Merge branch 'main' into remove-code-from-logs
edwinjosechittilappilly cf39af8
[autofix.ci] apply automated fixes
autofix-ci[bot] d051225
Merge branch 'main' into remove-code-from-logs
ogabrielluiz 81433b5
[autofix.ci] apply automated fixes
autofix-ci[bot] ad4b48e
[autofix.ci] apply automated fixes (attempt 2/3)
autofix-ci[bot] f3e20a4
refactor: improve code removal from logs with explicit dict copying
ogabrielluiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Tests package for langflow.""" | ||
|
|
||
| # Made with Bob |
3 changes: 3 additions & 0 deletions
3
src/backend/base/langflow/tests/services/database/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Database tests package.""" | ||
|
|
||
| # Made with Bob |
3 changes: 3 additions & 0 deletions
3
src/backend/base/langflow/tests/services/database/models/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Database models tests package.""" | ||
|
|
||
| # Made with Bob |
3 changes: 3 additions & 0 deletions
3
src/backend/base/langflow/tests/services/database/models/transactions/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| """Transaction models tests package.""" | ||
|
|
||
| # Made with Bob | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good work bob |
||
122 changes: 122 additions & 0 deletions
122
src/backend/base/langflow/tests/services/database/models/transactions/test_model.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import uuid | ||
| from datetime import datetime, timezone | ||
|
|
||
| import pytest | ||
| from langflow.services.database.models.transactions.model import TransactionBase | ||
|
|
||
|
|
||
| def test_serialize_inputs_excludes_code_key(): | ||
| """Test that the code key is excluded from inputs when serializing.""" | ||
| # Create a TransactionBase object with inputs containing a code key | ||
| transaction = TransactionBase( | ||
| timestamp=datetime.now(timezone.utc), | ||
| vertex_id="test-vertex", | ||
| target_id="test-target", | ||
| inputs={"param1": "value1", "param2": "value2", "code": "print('Hello, world!')"}, | ||
| outputs={"result": "success"}, | ||
| status="completed", | ||
| flow_id=uuid.uuid4(), | ||
| ) | ||
|
|
||
| # Get the serialized inputs | ||
| serialized_inputs = transaction.serialize_inputs(transaction.inputs) | ||
|
|
||
| # Verify that the code key is excluded | ||
| assert "code" not in serialized_inputs | ||
| assert "param1" in serialized_inputs | ||
| assert "param2" in serialized_inputs | ||
| assert serialized_inputs["param1"] == "value1" | ||
| assert serialized_inputs["param2"] == "value2" | ||
|
|
||
|
|
||
| def test_serialize_inputs_handles_none(): | ||
| """Test that the serialize_inputs method handles None inputs.""" | ||
| # Create a TransactionBase object with None inputs | ||
| transaction = TransactionBase( | ||
| timestamp=datetime.now(timezone.utc), | ||
| vertex_id="test-vertex", | ||
| target_id="test-target", | ||
| inputs=None, | ||
| outputs={"result": "success"}, | ||
| status="completed", | ||
| flow_id=uuid.uuid4(), | ||
| ) | ||
|
|
||
| # Get the serialized inputs | ||
| serialized_inputs = transaction.serialize_inputs(transaction.inputs) | ||
|
|
||
| # Verify that None is returned | ||
| assert serialized_inputs is None | ||
|
|
||
|
|
||
| def test_serialize_inputs_handles_non_dict(): | ||
| """Test that the serialize_inputs method handles non-dict inputs.""" | ||
| # Create a TransactionBase object with valid inputs | ||
| transaction = TransactionBase( | ||
| timestamp=datetime.now(timezone.utc), | ||
| vertex_id="test-vertex", | ||
| target_id="test-target", | ||
| inputs={}, # Empty dict is valid | ||
| outputs={"result": "success"}, | ||
| status="completed", | ||
| flow_id=uuid.uuid4(), | ||
| ) | ||
|
|
||
| # Call serialize_inputs directly with a non-dict value | ||
| serialized_inputs = transaction.serialize_inputs("not a dict") | ||
|
|
||
| # Verify that the input is returned as is | ||
| assert serialized_inputs == "not a dict" | ||
|
|
||
|
|
||
| def test_serialize_inputs_handles_empty_dict(): | ||
| """Test that the serialize_inputs method handles empty dict inputs.""" | ||
| # Create a TransactionBase object with empty dict inputs | ||
| transaction = TransactionBase( | ||
| timestamp=datetime.now(timezone.utc), | ||
| vertex_id="test-vertex", | ||
| target_id="test-target", | ||
| inputs={}, | ||
| outputs={"result": "success"}, | ||
| status="completed", | ||
| flow_id=uuid.uuid4(), | ||
| ) | ||
|
|
||
| # Get the serialized inputs | ||
| serialized_inputs = transaction.serialize_inputs(transaction.inputs) | ||
|
|
||
| # Verify that an empty dict is returned | ||
| assert serialized_inputs == {} | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_code_key_not_saved_to_database(): | ||
| """Test that the code key is not saved to the database.""" | ||
| # Create input data with a code key | ||
| input_data = {"param1": "value1", "param2": "value2", "code": "print('Hello, world!')"} | ||
|
|
||
| # Create a transaction with inputs containing a code key | ||
| transaction = TransactionBase( | ||
| timestamp=datetime.now(timezone.utc), | ||
| vertex_id="test-vertex", | ||
| target_id="test-target", | ||
| inputs=input_data, | ||
| outputs={"result": "success"}, | ||
| status="completed", | ||
| flow_id=uuid.uuid4(), | ||
| ) | ||
|
|
||
| # Verify that the code key is removed during transaction creation | ||
| assert transaction.inputs is not None | ||
| assert "code" not in transaction.inputs | ||
| assert "param1" in transaction.inputs | ||
| assert "param2" in transaction.inputs | ||
|
|
||
| # Verify that the code key is excluded when serializing | ||
| serialized_inputs = transaction.serialize_inputs(transaction.inputs) | ||
| assert "code" not in serialized_inputs | ||
| assert "param1" in serialized_inputs | ||
| assert "param2" in serialized_inputs | ||
|
|
||
|
|
||
| # Made with Bob |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.