Improve the file names of the Data Query attachment
- Dominant language
- Python
- Stars
- 26
- Forks
- 1
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 25
Description
### StatGPT Backend version
latest
### What is the problem this feature will solve?
When a CSV file is attached to a chat response, its file name is derived from `dataset.get_file_name()` (`statgpt/common/data/base/base.py:54`), which sanitizes the dataset's `entity_id`. For many datasets the `entity_id` is a UUID, so the resulting file name is something like `3f2a7b1c_8d4e_4f9a_b5c6_1a2b3c4d5e6f`.
When multiple data responses are merged, the file name becomes a concatenation of multiple UUIDs, making it even more meaningless to the user (e.g. `3f2a7b1c_8d4e_4f9a_b5c6_1a2b3c4d5e6f_7a8b9c0d_1e2f_3a4b_5c6d_7e8f9a0b1c2d`).
### What is the proposed feature or solution?
Generate a meaningful CSV file name based on available metadata, for example:
- Use the dataset's `source_id` and/or `name` (e.g. `GDP_annual_growth.csv`)
- Include a short indicator summary or query context when available
- Keep a reasonable length limit (e.g. 64 characters) and sanitize invalid filename characters
- Handle name collisions: when a user makes several queries against the same dataset in one conversation, the generated file names would be identical. Append a short disambiguator (counter suffix, short hash, or timestamp) to ensure uniqueness.
The display title of the attachment already uses `enrich_attachment_name()` with `{dataset_source_id}` / `{dataset_name}` placeholders, but the underlying **file name** (used for the actual stored/downloaded file) does not benefit from this.
### What alternatives have you considered?
Use the attachment **title** (already human-readable) as the file name — however, titles may contain characters unsupported in file names and don't handle collisions when the same dataset is queried multiple times
Contributor guide
Assessment
This issue has not been assessed yet.