-
Notifications
You must be signed in to change notification settings - Fork 3
Fix BED-8746: Add @app.defer decorator to handle generic exception handling
#37
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7f966fe
Add defer wrapper
d3vzer0 f0a17e5
Add safe_defer_wrapper to resource/transformers that return a defer f…
d3vzer0 9acde82
Updated defer decorator to mimic dlt behaviour
d3vzer0 9e7b981
Remove double wrapping, assume collectors need to use `@app.defer` an…
d3vzer0 3c15fbd
Remove unused resource_name input (since these are not always available)
d3vzer0 911cb40
Added test to see if the pipeline still continues with resource, tran…
d3vzer0 3597c3c
Remove unused ExampleResource model
d3vzer0 cf9938f
Remove unused ExampleResource model
d3vzer0 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
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,89 @@ | ||
| import logging | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
| from openhound.core.app import OpenHound | ||
| from openhound.core.collect import Collector | ||
| from openhound.core.progress import Progress | ||
|
|
||
|
|
||
| class Computer(BaseModel): | ||
| id: int | ||
| hostname: str | ||
|
|
||
|
|
||
| class User(BaseModel): | ||
| id: int | ||
| email: str | ||
|
|
||
|
|
||
| class UserDetails(User): | ||
| office: str | ||
|
|
||
|
|
||
| def test_dlt_wrapper_pipeline_continues( | ||
| caplog, | ||
| monkeypatch, | ||
| tmp_path, | ||
| ): | ||
| monkeypatch.setenv("DLT_DATA_DIR", str(tmp_path / ".dlt")) | ||
| monkeypatch.setattr( | ||
| "openhound.core.collect.logger_override.set_handler", lambda name: None | ||
| ) | ||
| caplog.set_level(logging.ERROR, logger="openhound.core.resources") | ||
|
|
||
| app = OpenHound("safe_wrapper_test", "TEST") | ||
|
|
||
| @app.resource(name="computers", columns=Computer) | ||
| def computers(): | ||
| yield {"id": 1, "hostname": "DESKTOP-12345"} | ||
| yield {"id": 2, "hostname": "DESKTOP-54321"} | ||
| raise RuntimeError("resource failed after valid rows") | ||
|
|
||
| @app.transformer(name="users", columns=User) | ||
| def users(computer): | ||
| if computer["id"] == 1: | ||
| yield {"id": 10, "email": "someuser@example.org"} | ||
| raise RuntimeError("transformer failed after valid row") | ||
|
|
||
| yield {"id": 20, "email": "someuser2@example.org"} | ||
|
|
||
| @app.transformer(name="user_details", columns=UserDetails) | ||
| def user_details(user): | ||
|
|
||
| @app.defer | ||
| def deferred_child(user_input): | ||
| if user_input["id"] == 1: | ||
| raise RuntimeError("defer failed for parent") | ||
|
|
||
| return {"id": 20, "email": "someuser2@example.org", "office": "Amsterdam"} | ||
|
|
||
| yield deferred_child(user) | ||
|
|
||
| @app.source(name="safe_wrapper_test", max_table_nesting=0) | ||
| def source(): | ||
| computers_resource = computers() | ||
| return ( | ||
| computers_resource, | ||
| computers_resource | users(), | ||
| computers_resource | user_details(), | ||
| ) | ||
|
|
||
| collector = Collector( | ||
| name="safe_wrapper_test", | ||
| output_path=tmp_path / "output", | ||
| progress=Progress.log, | ||
| ) | ||
|
|
||
| load_info = collector.run(source()) | ||
|
|
||
| assert load_info is not None | ||
|
|
||
| messages = [record.getMessage() for record in caplog.records] | ||
| phases = {getattr(record, "phase", None) for record in caplog.records} | ||
|
|
||
| assert any("resource failed after valid rows" in message for message in messages) | ||
| assert any("transformer failed after valid row" in message for message in messages) | ||
| assert any("defer failed for parent" in message for message in messages) | ||
| assert "resource_iteration" in phases | ||
| assert "defer_execution" in phases |
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.