From c03a354b0c4c951d97639d0fc700fa795a262b3a Mon Sep 17 00:00:00 2001 From: Sultan Iman Date: Tue, 2 Apr 2024 17:17:30 +0200 Subject: [PATCH] Fix current datetime resolution --- dlt/destinations/impl/filesystem/layout.py | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/dlt/destinations/impl/filesystem/layout.py b/dlt/destinations/impl/filesystem/layout.py index 7ebb4f00fe..e491c56fee 100644 --- a/dlt/destinations/impl/filesystem/layout.py +++ b/dlt/destinations/impl/filesystem/layout.py @@ -86,25 +86,27 @@ def params(self) -> Optional[Dict[str, Any]]: "ext": self.file_format, } ) + # If current_datetime is a callable # then we need to inspect it's return type # if return type is not DateTime # then call it and check it's instance # if it is not DateTime then exit. - if self.config.current_datetime is not None: - if callable(self.config.current_datetime): - result = self.config.current_datetime() - if isinstance(result, pendulum.DateTime): - self.current_datetime = result - else: - raise RuntimeError( - "current_datetime was passed as callable but " - "didn't return any instance of pendulum.DateTime" - ) - else: + if not self.config.current_datetime: self.config.current_datetime = pendulum.now() + elif callable(self.config.current_datetime): + result = self.config.current_datetime() + if isinstance(result, pendulum.DateTime): + self.current_datetime = result + else: + raise RuntimeError( + "current_datetime was passed as callable but " + "didn't return any instance of pendulum.DateTime" + ) now: pendulum.DateTime = self.config.current_datetime # type: ignore[assignment] + # For each callable extra parameter + # otherwise take it's value for key, value in self.config.extra_params.items(): if callable(value): self._params[key] = value(