john-bodley commented on code in PR #25950: URL: https://github.com/apache/superset/pull/25950#discussion_r1389898080
########## superset/jinja_context.py: ########## @@ -486,6 +487,26 @@ def process_template(self, sql: str, **kwargs: Any) -> str: class JinjaTemplateProcessor(BaseTemplateProcessor): + def _parse_datetime(self, dttm: Optional[str]) -> Optional[datetime]: + """ + Try to parse a datetime and default to None in the worst case. + + Since this may have been rendered by different engines, the datetime may + vary slightly in format. We try to make it consistent, and if all else + fails, just return None. + """ + if not dttm: Review Comment: Rather than making `dttm` optional could you add the check in the caller? ########## superset/jinja_context.py: ########## @@ -486,6 +487,26 @@ def process_template(self, sql: str, **kwargs: Any) -> str: class JinjaTemplateProcessor(BaseTemplateProcessor): + def _parse_datetime(self, dttm: Optional[str]) -> Optional[datetime]: + """ + Try to parse a datetime and default to None in the worst case. + + Since this may have been rendered by different engines, the datetime may + vary slightly in format. We try to make it consistent, and if all else + fails, just return None. + """ + if not dttm: + return None + + dttm_format = "%Y-%m-%dT%H:%M:%S.%f" Review Comment: I think `dateutils.parser.parse` is likely the preferred method of converting a `str` to a `datetime` object. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org