Skip to content

Commit

Permalink
Add deprecation warning for credentials argument
Browse files Browse the repository at this point in the history
  • Loading branch information
steinitzu committed Nov 16, 2023
1 parent fe24e14 commit 481a7cb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dlt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from dlt.extract.decorators import source, resource, transformer, defer
from dlt.pipeline import pipeline as _pipeline, run, attach, Pipeline, dbt, current as _current, mark as _mark
from dlt.pipeline import progress
from dlt import destinations

pipeline = _pipeline
current = _current
Expand Down Expand Up @@ -64,4 +65,5 @@
"TSecretValue",
"TCredentials",
"sources",
"destinations",
]
3 changes: 3 additions & 0 deletions dlt/pipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dlt.pipeline.configuration import PipelineConfiguration, ensure_correct_pipeline_kwargs
from dlt.pipeline.pipeline import Pipeline
from dlt.pipeline.progress import _from_name as collector_from_name, TCollectorArg, _NULL_COLLECTOR
from dlt.pipeline.deprecations import credentials_argument_deprecated


@overload
Expand Down Expand Up @@ -104,6 +105,8 @@ def pipeline(
# is any of the arguments different from defaults
has_arguments = bool(orig_args[0]) or any(orig_args[1].values())

credentials_argument_deprecated("pipeline", credentials, destination)

if not has_arguments:
context = Container()[PipelineContext]
# if pipeline instance is already active then return it, otherwise create a new one
Expand Down
20 changes: 20 additions & 0 deletions dlt/pipeline/deprecations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import typing as t
import warnings

from dlt.common.destination import Destination, TDestinationReferenceArg


def credentials_argument_deprecated(
caller_name: str, credentials: t.Optional[t.Any], destination: TDestinationReferenceArg = None
) -> None:
if credentials is None:
return

dest_name = Destination.to_name(destination) if destination else "postgres"

warnings.warn(
f"The `credentials argument` to {caller_name} is deprecated and will be removed in a future version. "
f"Pass the same credentials to the `destination` instance instead, e.g. {caller_name}(destination=dlt.destinations.{dest_name}(credentials=...))",
DeprecationWarning,
stacklevel=2,
)
6 changes: 6 additions & 0 deletions dlt/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from dlt.pipeline.state_sync import STATE_ENGINE_VERSION, load_state_from_destination, merge_state_if_changed, migrate_state, state_resource, json_encode_state, json_decode_state

from dlt.common.schema.utils import normalize_schema_name
from dlt.pipeline.deprecations import credentials_argument_deprecated


def with_state_sync(may_extract_state: bool = False) -> Callable[[TFun], TFun]:
Expand Down Expand Up @@ -342,6 +343,9 @@ def load(
# set destination and default dataset if provided
self._set_destinations(destination, None)
self._set_dataset_name(dataset_name)

credentials_argument_deprecated("pipeline.load", credentials, destination)

self.credentials = credentials or self.credentials

# check if any schema is present, if not then no data was extracted
Expand Down Expand Up @@ -449,6 +453,8 @@ def run(
self._set_destinations(destination, staging)
self._set_dataset_name(dataset_name)

credentials_argument_deprecated("pipeline.run", credentials, self.destination)

# sync state with destination
if self.config.restore_from_destination and not self.full_refresh and not self._state_restored and (self.destination or destination):
self.sync_destination(destination, staging, dataset_name)
Expand Down

0 comments on commit 481a7cb

Please sign in to comment.