Bungic commented on code in PR #40801:
URL: https://github.com/apache/superset/pull/40801#discussion_r3362426624
##########
superset/views/base.py:
##########
@@ -727,12 +727,21 @@ def apply(self, query: Query, value: Any) -> Query:
class CsvResponse(Response):
"""
- Override Response to take into account csv encoding from config.py
+ Response that encodes its body with the configured CSV_EXPORT encoding.
+
+ Werkzeug 3.0 removed ``Response.charset``, which this class relied on,
+ so the configured encoding (e.g. the default "utf-8-sig") was silently
+ ignored and bodies were always plain utf-8.
"""
- charset = app.config["CSV_EXPORT"].get("encoding", "utf-8")
default_mimetype = "text/csv"
+ def __init__(self, response: Any = None, *args: Any, **kwargs: Any) ->
None:
+ encoding = app.config["CSV_EXPORT"].get("encoding", "utf-8")
+ if isinstance(response, str):
+ response = response.encode(encoding)
Review Comment:
CSV_EXPORT cannot be absent in a Superset app: it is defined unconditionally
in superset/config.py, and every other read in the codebase subscripts it
directly (charts/data/api.py, viz.py, common/query_context_processor.py,
commands/sql_lab/export.py). Switching to .get("CSV_EXPORT", {}) here would
imply the key is optional when it is not, and CsvResponse is internal to
Superset rather than a generic Flask utility, so I would rather keep the access
consistent and fail loudly on a broken config.
The bytes point is fair though: moved the config read inside the str branch
in 7cb5d14, so byte payloads no longer touch config at all.
--
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]