Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dlt/destinations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+))?\)")

Expand All @@ -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):
Copy link
Collaborator

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

raise Exception(
"You are trying to use an adapter on a dlt source. You can only use adapters on pure"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function only used with adapters? The error message seems to be out of context for ensure_resource function. Also, TypeError maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it only is used in adapters, I checked that.

" data or dlt resources."
)
resource_name = None if hasattr(data, "__name__") else "content"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this else close should throw a warning. Otherwise, you get some unrecognizable table in the destination with the name Content out of nowhere 😱

return cast(DltResource, make_resource(data, name=resource_name))

Expand Down