Skip to content
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

Fix the order of checks for in-memory duckdb option #1333

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions dlt/destinations/impl/duckdb/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ def is_partial(self) -> bool:
return self.database == ":pipeline:"

def on_resolved(self) -> None:
if isinstance(self.database, str) and self.database == ":memory:":
raise InvalidInMemoryDuckdbCredentials()

# do not set any paths for external database
if self.database == ":external:":
return
Expand All @@ -138,6 +135,12 @@ def on_resolved(self) -> None:
is_default_path = maybe_is_default_path
self.database = maybe_database

# We need to check it here because the default `native_value` for duckdb is :memory:
# thus if we do this check at the very beginning we will fail the default usecase
# when users just specify destination="duckdb" thus it is undesired behavior.
if isinstance(self.database, str) and self.database == ":memory:":
raise InvalidInMemoryDuckdbCredentials()

# always make database an abs path
self.database = os.path.abspath(self.database)
# do not save the default path into pipeline's local state
Expand Down
6 changes: 5 additions & 1 deletion tests/load/duckdb/test_duckdb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def test_duckdb_in_memory_mode_via_factory(preserve_environ):

# Check if passing external duckdb connection works fine
db = duckdb.connect(":memory:")
dlt.pipeline(pipeline_name="booboo", destination=dlt.destinations.duckdb(db))
p = dlt.pipeline(pipeline_name="booboo", destination=dlt.destinations.duckdb(db))
p.run()

p = dlt.pipeline(pipeline_name="normal-pipeline-with-duckdb", destination="duckdb")
p.run()

# Check if passing :memory: to factory fails
with pytest.raises(PipelineStepFailed) as exc:
Expand Down
Loading