Skip to content

Commit

Permalink
Fix current datetime resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
sultaniman committed Apr 2, 2024
1 parent 4f7c1dc commit c03a354
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions dlt/destinations/impl/filesystem/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c03a354

Please sign in to comment.