frafra edited a comment on issue #15905: URL: https://github.com/apache/superset/issues/15905#issuecomment-929226661
There are various places in the code where such method is used as default when dumping the JSON (look for `default=json_int_dttm_ser`): https://github.com/apache/superset/blob/1669947bcd429e926c6e8de5ceaafcfe5496b28b/superset/charts/api.py#L518-L523 https://github.com/apache/superset/blob/0f16177bde156163643c55e5cd24fab996f40971/superset/utils/core.py#L618-L619 ...and others. Here is the problematic function: https://github.com/apache/superset/blob/0f16177bde156163643c55e5cd24fab996f40971/superset/utils/core.py#L604-L615 It was meant to handle date, datetime, but not time. It actually uses a generic function before trying to dealing with date and datetime, such `base_json_conv`: https://github.com/apache/superset/blob/0f16177bde156163643c55e5cd24fab996f40971/superset/utils/core.py#L550-L573 It would be enough to add a specific case: ``` > python3 Python 3.8.10 (default, May 05 2021, 15:36:36) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import datetime >>> str(datetime.time()) '00:00:00' ``` The function `json_iso_dttm_ser` is almost identical, but it tries to convert to ISO format instead of an integer, and it has support for `time`: https://github.com/apache/superset/blob/27a40d2a675fc2f9031eb1c072da046248c069ea/superset/utils/core.py#L587-L588 In case of `time`, `.isoformat()` is equivalent to `str(...)`: ` __str__ = isoformat` (https://github.com/python/cpython/blob/84975146a7ce64f1d50dcec8311b7f7188a5c962/Lib/datetime.py#L1434) As a time without a date cannot be converted to an integer with respect to EPOCH, we should decide if it would make more sense to convert it to seconds (from the beginning of the midnight) or to a string. `datetime.time` has no `total_seconds()` method or similar, so I would suggest converting it to a string, which seems the safest solution. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
