bito-code-review[bot] commented on PR #41060:
URL: https://github.com/apache/superset/pull/41060#issuecomment-4710834374
<!-- Bito Reply -->
The flagged issue is correct. The current implementation of
`_python_date_format` relies solely on attribute access (`hasattr(column_obj,
"python_date_format")`), which fails when `get_column()` returns a
dictionary-based column metadata object. To resolve this, `_python_date_format`
should be updated to check for the key in the dictionary if the object is a
mapping, mirroring the logic used in `_is_dttm`.
Here is the corrected implementation for `superset/models/helpers.py`:
```python
def _python_date_format(self, column: str | None) -> str | None:
"""Return the column's configured ``python_date_format`` (e.g.
``epoch_s``
or a strftime pattern), or ``None`` if the column declares no
format."""
if not hasattr(self, "get_column") or not (column_obj :=
self.get_column(column)):
return None
if isinstance(column_obj, dict):
return column_obj.get("python_date_format")
if hasattr(column_obj, "python_date_format"):
return str(column_obj.python_date_format)
return None
```
**superset/models/helpers.py**
```
def _python_date_format(self, column: str | None) -> str | None:
"""Return the column's configured ``python_date_format`` (e.g.
``epoch_s``
or a strftime pattern), or ``None`` if the column declares no
format."""
if not hasattr(self, "get_column") or not (column_obj :=
self.get_column(column)):
return None
if isinstance(column_obj, dict):
return column_obj.get("python_date_format")
if hasattr(column_obj, "python_date_format"):
return str(column_obj.python_date_format)
return None
```
--
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]