-
Notifications
You must be signed in to change notification settings - Fork 419
prevent accidental wrapping of sources in resources when using adapters #1645
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
Changes from 2 commits
f86c90d
bc3030a
fd45350
1a91659
1d6a18f
4b00b4b
8f37964
bccbbba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| from typing import Any, cast, Tuple, Dict, Type | ||
|
|
||
| from dlt.destinations.exceptions import DatabaseTransientException | ||
| from dlt.extract import DltResource, resource as make_resource | ||
| from dlt.extract import DltResource, resource as make_resource, DltSource | ||
|
|
||
| RE_DATA_TYPE = re.compile(r"([A-Z]+)\((\d+)(?:,\s?(\d+))?\)") | ||
|
|
||
|
|
@@ -23,6 +23,12 @@ def ensure_resource(data: Any) -> DltResource: | |
| """Wraps `data` in a DltResource if it's not a DltResource already.""" | ||
| if isinstance(data, DltResource): | ||
| return data | ||
| # prevent accidentally wrapping sources with adapters | ||
| if isinstance(data, DltSource): | ||
| raise Exception( | ||
| "You are trying to use an adapter on a dlt source. You can only use adapters on pure" | ||
|
||
| " data or dlt resources." | ||
| ) | ||
| resource_name = None if hasattr(data, "__name__") else "content" | ||
|
||
| return cast(DltResource, make_resource(data, name=resource_name)) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you check if source selects just one resource and then adapt it? look here: #1644 I think the user's thinking is OK