You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "ampil (via GitHub)" <gi...@apache.org> on 2025/05/18 19:09:35 UTC

[D] Get dataset description and columns description [superset]

GitHub user ampil created a discussion: Get dataset description and columns description

During the Excel export, I want to include dataset description and column descriptions.
I’d like to place them on a separate sheet in the output XLSX file.

From what I've found, I need to modify these two files:
1. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)
/core.py
2. [superset](https://github.com/apache/superset/tree/master)/[superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)
/excel.py

However, I couldn’t find the description fields in core.py for either the dataset or its columns.
Could you suggest how to implement this? 

@dosu

GitHub link: https://github.com/apache/superset/discussions/33504

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
In Superset, the `dataset` object is typically accessed through the `DatasetDAO` class, which provides methods for interacting with datasets in the database. To retrieve a dataset object in `excel.py`, you can use the `get_dataset_by_id` method from `DatasetDAO`. Here's an example of how you might implement this:

1. **Import the necessary module**: Ensure you import the `DatasetDAO` class in your `excel.py` file.

```python
from superset.daos.dataset import DatasetDAO
```

2. **Retrieve the dataset object**: Use the `get_dataset_by_id` method to fetch the dataset object using its ID.

```python
def get_dataset_by_id(dataset_id: int):
    # Use DatasetDAO to retrieve the dataset object
    dataset = DatasetDAO.find_by_id(dataset_id)
    return dataset
```

3. **Access dataset properties**: Once you have the dataset object, you can access its properties, such as descriptions and columns.

```python
def get_dataset_description_and_columns(dataset_id: int):
    dataset = get_dataset_by_id(dataset_id)
    if not dataset:
        return None, None

    # Access dataset description
    dataset_description = dataset.description

    # Access column descriptions
    column_descriptions = {column.column_name: column.description for column in dataset.columns}

    return dataset_description, column_descriptions
```

This code provides a way to retrieve the dataset object and access its description and column metadata, which you can then use in your Excel export logic in `excel.py` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/daos/dataset.py)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2d271908-91fd-4c3e-b613-38e0ffb446c0?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186331

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

@dosu

Provide code how to access the Dataset ID `requested_ids` parameter in the `export` method of the `DatasetRestApi` class. 
Provide code on how the dataset ID can be defined in the `excel.py`.

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186418

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
To obtain the `query_context_payload` related to the chart you're trying to download, you can use the `get_data` method in the `ChartDataRestApi` class. This method retrieves the query context stored when the chart was saved using the chart ID. Here's a relevant code snippet:

```python
@expose("/<int:pk>/data/", methods=("GET",))
@protect()
@statsd_metrics
@event_logger.log_this_with_context(
    action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.data",
    log_to_statsd=False,
)
def get_data(self, pk: int) -> Response:
    chart = self.datamodel.get(pk, self._base_filters)
    if not chart:
        return self.response_404()

    try:
        json_body = json.loads(chart.query_context)
    except (TypeError, json.JSONDecodeError):
        json_body = None

    if json_body is None:
        return self.response_400(
            message=_(
                "Chart has no query context saved. Please save the chart again."
            )
        )

    # override saved query context
    json_body["result_format"] = request.args.get(
        "format", ChartDataResultFormat.JSON
    )
    json_body["result_type"] = request.args.get("type", ChartDataResultType.FULL)
    json_body["force"] = request.args.get("force")

    try:
        query_context = self._create_query_context_from_form(json_body)
        command = ChartDataCommand(query_context)
        command.validate()
    except DatasourceNotFound:
        return self.response_404()
    except QueryObjectValidationError as error:
        return self.response_400(message=error.message)
    except ValidationError as error:
        return self.response_400(
            message=_(
                "Request is incorrect: %(error)s", error=error.normalized_messages()
            )
        )

    # TODO: support CSV, SQL query and other non-JSON types
    if (
        is_feature_enabled("GLOBAL_ASYNC_QUERIES")
        and query_context.result_format == ChartDataResultFormat.JSON
        and query_context.result_type == ChartDataResultType.FULL
    ):
        return self._run_async(json_body, command)

    try:
        form_data = json.loads(chart.params)
    except (TypeError, json.JSONDecodeError):
        form_data = {}

    return self._get_data_response(
        command=command, form_data=form_data, datasource=query_context.datasource
    )
```

This method uses the chart ID (`pk`) to fetch the query context and returns the payload data response. You can access the real value of the `query_context_payload` by examining the `json_body` variable after it is loaded from `chart.query_context` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/charts/data/api.py)</sup>.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=c565ba71-572f-4300-99a1-c1b5297265da) [![Learn about superset with Dosu](https://img.shields.io/badge/Learn%20about%20superset%20with%20Dosu-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS4yOTIzNiAxMi43OTI4TDE3Ljc1OTMgNi42ODE4OFY3Mi41NjY3TDUuMjkyMzYgODQuMDYxOFYxMi43OTI4WiIgZmlsbD0iI0I0QkI5MSIvPjxwYXRoIGQ9Ik0xOC4yNTc1IDczLjExOTZMNTkuMTMyOSA3Mi43NDhMNTEuNzAxMSA4Mi40MDk1TDI5LjAzMzggODYuMjkxTDYuMjM5NjIgODUuMTU1NEwxOC4yNTc1IDczLjExOTZaIiBmaW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va2U9ImJsYWNrIiB
 zdHJva2Utd2lkdGg9IjcuNjkxNjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0wLjM0ODYzMyA4NS40OTQ2QzAuMzQ4NjMzIDg1LjQ5NDYgMjkuNDg1NiA4NS44MzA5IDM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [![Add Dosu to your team](https://img.shields.io/badge/Add%20Dosu%20to%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13190842

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

@dosu 
How do I get the `query_context_payload` related to the chart I'm trying to download? So I can see its real value in `excel.py`?

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13190795

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
To modify the `superset/datasets/schemas.py` and `core.py` files to read `dataset_description` and `column_descriptions` for use in `excel.py`, follow these steps:

1. **Modify `superset/datasets/schemas.py`**: Ensure that the dataset and column descriptions are accessible. This file already includes schema classes with description fields, so you might not need to modify it directly. However, ensure that these fields are being populated correctly when datasets and columns are created or updated.

2. **Modify `core.py`**: You need to create functions to retrieve the dataset and column descriptions. Here's a basic example of how you might implement these functions:

```python
def get_dataset_description(dataset_id: int) -> str:
    # Fetch the dataset description from the database using the dataset_id
    # This is a placeholder implementation; replace it with actual database access logic
    dataset = get_dataset_by_id(dataset_id)  # Assume this function fetches the dataset object
    return dataset.description if dataset else ""

def get_column_descriptions(dataset_id: int) -> dict:
    # Fetch column descriptions for a given dataset_id
    # This is a placeholder implementation; replace it with actual database access logic
    dataset = get_dataset_by_id(dataset_id)  # Assume this function fetches the dataset object
    if not dataset:
        return {}

    column_descriptions = {}
    for column in dataset.columns:
        column_descriptions[column.name] = column.description

    return column_descriptions
```

3. **Integrate with `excel.py`**: Use these functions to retrieve descriptions and pass them to the `df_to_excel_with_descriptions` function. Here's how you might call these functions and use them in `excel.py`:

```python
def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve descriptions
    dataset_description = get_dataset_description(dataset_id)
    column_descriptions = get_column_descriptions(dataset_id)

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs)
```

Ensure that you replace the placeholder logic in `get_dataset_description` and `get_column_descriptions` with actual database queries or ORM calls to fetch the dataset and column descriptions from your data source.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186262

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil edited a discussion: Get dataset description and columns description

During the Excel export, I want to include dataset description and column descriptions.
I’d like to place them on a separate sheet in the output XLSX file.

From what I've found, I need to modify these two files:
1. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)/core.py
2. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)/excel.py

However, I couldn’t find the description fields in core.py for either the dataset or its columns.
Could you suggest how to implement this? 

@dosu

GitHub link: https://github.com/apache/superset/discussions/33504

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

What is the actual `dataset` access logic in Superset? How can I get the `dataset` object in the `excel.py`?
Provide related code.
@dosu

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186317

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

How do I get the `dataset_id`?
How to modify `excel.py` and/or other files to retrieve the dataset id exported to Excel?

@dosu

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186351

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

@dosu
When I choose "Download" -> "Export to Excel" on a chart, the chart data is downloaded as XLSX.
It uses `df_to_excel` from `excel.py`.

Should the `dataset_id` be accessible when saving the chart data to Excel?

I need to provide `dataset_id` to the `df_to_excel`. It's clear how change a code to pass a `dataset_id` parameter .
But it's unclear how to get the real physical value of `dataset_id` to `df_to_excel`.

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13189374

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
To access the `requested_ids` parameter in the `export` method of the `DatasetRestApi` class, you can follow the existing implementation where `requested_ids` is extracted from the `kwargs` using the key `"rison"`. Here's how it's done:

```python
@expose("/export/", methods=("GET",))
@protect()
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this_with_context(
    action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.export",
    log_to_statsd=False,
)
def export(self, **kwargs: Any) -> Response:
    """Download multiple datasets as YAML files."""
    requested_ids = kwargs["rison"]
    # Further processing with requested_ids
```

In this method, `requested_ids` contains the IDs of the datasets to be exported <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/api.py)</sup>.

To define and use the dataset ID in `excel.py`, you can modify the export function to accept a `dataset_id` parameter. Here's an example of how you might implement this:

```python
from superset.daos.dataset import DatasetDAO

def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve the dataset object using the dataset ID
    dataset = DatasetDAO.find_by_id(dataset_id)
    if not dataset:
        raise ValueError("Dataset not found")

    # Access dataset description and column descriptions
    dataset_description = dataset.description
    column_descriptions = {column.column_name: column.description for column in dataset.columns}

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs)
```

In this code, `dataset_id` is used to fetch the dataset object and its metadata, which are then included in the Excel export. Ensure that the function responsible for initiating the export process passes the correct `dataset_id` to this function.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/e81e51d4-30b8-4e33-946d-75d0bcc701e1?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186421

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
To obtain the `query_context_payload` related to the chart you're trying to download, you can use the `get_data` method in the `ChartDataRestApi` class. This method retrieves the query context stored when the chart was saved using the chart ID. Here's a relevant code snippet:

```python
@expose("/<int:pk>/data/", methods=("GET",))
@protect()
@statsd_metrics
@event_logger.log_this_with_context(
    action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.data",
    log_to_statsd=False,
)
def get_data(self, pk: int) -> Response:
    chart = self.datamodel.get(pk, self._base_filters)
    if not chart:
        return self.response_404()

    try:
        json_body = json.loads(chart.query_context)
    except (TypeError, json.JSONDecodeError):
        json_body = None

    if json_body is None:
        return self.response_400(
            message=_(
                "Chart has no query context saved. Please save the chart again."
            )
        )

    # override saved query context
    json_body["result_format"] = request.args.get(
        "format", ChartDataResultFormat.JSON
    )
    json_body["result_type"] = request.args.get("type", ChartDataResultType.FULL)
    json_body["force"] = request.args.get("force")

    try:
        query_context = self._create_query_context_from_form(json_body)
        command = ChartDataCommand(query_context)
        command.validate()
    except DatasourceNotFound:
        return self.response_404()
    except QueryObjectValidationError as error:
        return self.response_400(message=error.message)
    except ValidationError as error:
        return self.response_400(
            message=_(
                "Request is incorrect: %(error)s", error=error.normalized_messages()
            )
        )

    # TODO: support CSV, SQL query and other non-JSON types
    if (
        is_feature_enabled("GLOBAL_ASYNC_QUERIES")
        and query_context.result_format == ChartDataResultFormat.JSON
        and query_context.result_type == ChartDataResultType.FULL
    ):
        return self._run_async(json_body, command)

    try:
        form_data = json.loads(chart.params)
    except (TypeError, json.JSONDecodeError):
        form_data = {}

    return self._get_data_response(
        command=command, form_data=form_data, datasource=query_context.datasource
    )
```

This method uses the chart ID (`pk`) to fetch the query context and returns the payload data response. You can access the real value of the `query_context_payload` by examining the `json_body` variable after it is loaded from `chart.query_context` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/charts/data/api.py)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c565ba71-572f-4300-99a1-c1b5297265da?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13190842

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
To access the `requested_ids` parameter in the `export` method of the `DatasetRestApi` class, you can follow the existing implementation where `requested_ids` is extracted from the `kwargs` using the key `"rison"`. Here's how it's done:

```python
@expose("/export/", methods=("GET",))
@protect()
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this_with_context(
    action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.export",
    log_to_statsd=False,
)
def export(self, **kwargs: Any) -> Response:
    """Download multiple datasets as YAML files."""
    requested_ids = kwargs["rison"]
    # Further processing with requested_ids
```

In this method, `requested_ids` contains the IDs of the datasets to be exported <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/api.py)</sup>.

To define and use the dataset ID in `excel.py`, you can modify the export function to accept a `dataset_id` parameter. Here's an example of how you might implement this:

```python
from superset.daos.dataset import DatasetDAO

def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve the dataset object using the dataset ID
    dataset = DatasetDAO.find_by_id(dataset_id)
    if not dataset:
        raise ValueError("Dataset not found")

    # Access dataset description and column descriptions
    dataset_description = dataset.description
    column_descriptions = {column.column_name: column.description for column in dataset.columns}

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs)
```

In this code, `dataset_id` is used to fetch the dataset object and its metadata, which are then included in the Excel export. Ensure that the function responsible for initiating the export process passes the correct `dataset_id` to this function.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Docs are dead. Just use [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-feedback&utm_term=apache%2Fsuperset&message_id=e81e51d4-30b8-4e33-946d-75d0bcc701e1) [![Ask Dosu about superset](https://img.shields.io/badge/Ask%20Dosu%20about%20superset-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS4yOTIzNiAxMi43OTI4TDE3Ljc1OTMgNi42ODE4OFY3Mi41NjY3TDUuMjkyMzYgODQuMDYxOFYxMi43OTI4WiIgZmlsbD0iI0I0QkI5MSIvPjxwYXRoIGQ9Ik0xOC4yNTc1IDczLjExOTZMNTkuMTMyOSA3Mi43NDhMNTEuNzAxMSA4Mi40MDk1TDI5LjAzMzggODYuMjkxTDYuMjM5NjIgODUuMTU1NEwxOC4yNTc1IDczLjExOTZaIiBmaWxsPSIjNzc4NTYxIi8%2BPHBhdGggZD0iTTE3LjQ5MTYgMy43MzYzM0wzLjU4NTU3IDEyLjcwOTlWODMuNTc5MkMzLjU4NTU3IDg0Ljc1NDIgNC45ODU2MyA4NS4zNjUyIDUuODQ3MDUg
 ODQuNTY2TDE5LjYyOTYgNzEuNzgwMSIgc3Ryb2tlPSJibGFjayIgc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DM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-ask-repo&utm_term=apache%2Fsuperset) [![Share Dosu with your team](https://img.shields.io/badge/Share%20Dosu%20with%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=static-docs-share-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186421

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
To retrieve the `dataset_id` for exporting to Excel, you can follow these steps:

1. **Access the Dataset ID**: The dataset ID is typically passed as part of the export operation. In the Superset codebase, the dataset ID is accessed through the `requested_ids` parameter in the `export` method of the `DatasetRestApi` class. This method uses the `ExportDatasetsCommand` to handle the export operation, which takes `requested_ids` as an argument to specify which datasets to export <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/api.py)</sup>.

2. **Modify `excel.py`**: To use the dataset ID in `excel.py`, you need to ensure that the ID is passed to the functions responsible for exporting data. You can modify the function that initiates the export process to accept a `dataset_id` parameter and use it to fetch the dataset object and its metadata.

Here's an example of how you might modify the `excel.py` file to include the dataset ID in the export process:

```python
from superset.daos.dataset import DatasetDAO

def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve the dataset object using the dataset ID
    dataset = DatasetDAO.find_by_id(dataset_id)
    if not dataset:
        raise ValueError("Dataset not found")

    # Access dataset description and column descriptions
    dataset_description = dataset.description
    column_descriptions = {column.column_name: column.description for column in dataset.columns}

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs)
```

3. **Integrate with the Export Process**: Ensure that the function responsible for handling the export operation (e.g., `handleBulkDatasetExport`) passes the dataset ID to the `export_to_excel` function. This way, you can retrieve the dataset object and its metadata for inclusion in the Excel export.

By following these steps, you can effectively retrieve and use the `dataset_id` during the Excel export process in Superset.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=342e4212-f02a-4b9f-8c8c-edb0197a5b54) [![Learn about superset with Dosu](https://img.shields.io/badge/Learn%20about%20superset%20with%20Dosu-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS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3OTE5SDQwLjcwNFY3LjYxNTMyWiIgZmlsbD0iYmxhY2siIG1hc2s9InVybCgjZG9zdS1kLWN1dG91dCkiLz48cGF0aCBkPSJNNjguOTIxNSAzNi4wMTM1QzY4LjkyMTUgMzYuMDEzNSA2NS43MzY5IDQ5LjQ3MzggNTEuNDIzMSA0OS40NzM4QzM3LjEwOTMgNDkuNDczOCAzMi41Nzg3IDM3LjM1OTYgMzIuNTc4NyAzNi4wMTM1IiBzdHJva2U9ImJsYWNrIiB
 zdHJva2Utd2lkdGg9IjcuNjkxNjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0wLjM0ODYzMyA4NS40OTQ2QzAuMzQ4NjMzIDg1LjQ5NDYgMjkuNDg1NiA4NS44MzA5IDM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [![Add Dosu to your team](https://img.shields.io/badge/Add%20Dosu%20to%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186356

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
To include dataset and column descriptions in the Excel export, you can follow these steps:

1. **Retrieve Descriptions**: First, ensure you have access to the dataset and column descriptions. These are defined in various parts of the Superset codebase, such as in the `superset/datasets/schemas.py` file and the frontend interface in `superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/schemas.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts)</sup>.

2. **Modify `core.py`**: Although `core.py` does not directly handle descriptions, you can use functions like `get_column_name` and `get_column_names` to retrieve column metadata. You might need to extend these functions or create new ones to fetch descriptions if they are not already included <sup>[[3]](https://github.com/apache/superset/blob/master/tests/unit_tests/core_tests.py)</sup>.

3. **Modify `excel.py`**: In `excel.py`, you can modify the `df_to_excel` function to add a new sheet for descriptions. Use the `xlsxwriter` library to create a workbook and add worksheets. Here's a basic example of how you can add a new sheet for descriptions:

```python
import io
import pandas as pd
import xlsxwriter

def df_to_excel_with_descriptions(df: pd.DataFrame, dataset_description: str, column_descriptions: dict, **kwargs: Any) -> Any:
    output = io.BytesIO()

    # Quote formulas to prevent malicious injections
    df = quote_formulas(df)

    with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
        # Write the main data to the first sheet
        df.to_excel(writer, sheet_name='Data', **kwargs)

        # Add a new sheet for descriptions
        workbook = writer.book
        description_sheet = workbook.add_worksheet('Descriptions')

        # Write dataset description
        description_sheet.write(0, 0, 'Dataset Description')
        description_sheet.write(0, 1, dataset_description)

        # Write column descriptions
        description_sheet.write(1, 0, 'Column Name')
        description_sheet.write(1, 1, 'Description')
        row = 2
        for column, description in column_descriptions.items():
            description_sheet.write(row, 0, column)
            description_sheet.write(row, 1, description)
            row += 1

    return output.getvalue()
```

In this example, `dataset_description` is a string containing the dataset's description, and `column_descriptions` is a dictionary where keys are column names and values are their descriptions. You will need to pass these to the function when calling it.

By implementing these changes, you can include the dataset and column descriptions in a separate sheet in the exported Excel file.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6373ebbc-40a1-40ae-bd70-c40954a1cd48?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186210

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
To retrieve the `dataset_id` for exporting to Excel, you can follow these steps:

1. **Access the Dataset ID**: The dataset ID is typically passed as part of the export operation. In the Superset codebase, the dataset ID is accessed through the `requested_ids` parameter in the `export` method of the `DatasetRestApi` class. This method uses the `ExportDatasetsCommand` to handle the export operation, which takes `requested_ids` as an argument to specify which datasets to export <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/api.py)</sup>.

2. **Modify `excel.py`**: To use the dataset ID in `excel.py`, you need to ensure that the ID is passed to the functions responsible for exporting data. You can modify the function that initiates the export process to accept a `dataset_id` parameter and use it to fetch the dataset object and its metadata.

Here's an example of how you might modify the `excel.py` file to include the dataset ID in the export process:

```python
from superset.daos.dataset import DatasetDAO

def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve the dataset object using the dataset ID
    dataset = DatasetDAO.find_by_id(dataset_id)
    if not dataset:
        raise ValueError("Dataset not found")

    # Access dataset description and column descriptions
    dataset_description = dataset.description
    column_descriptions = {column.column_name: column.description for column in dataset.columns}

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs)
```

3. **Integrate with the Export Process**: Ensure that the function responsible for handling the export operation (e.g., `handleBulkDatasetExport`) passes the dataset ID to the `export_to_excel` function. This way, you can retrieve the dataset object and its metadata for inclusion in the Excel export.

By following these steps, you can effectively retrieve and use the `dataset_id` during the Excel export process in Superset.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/342e4212-f02a-4b9f-8c8c-edb0197a5b54?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186356

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

@dosu

Provide code samples on how to modify `superset/datasets/schemas.py`, `core.py` to read `dataset_description` and `column_descriptions` dictionary in the `excel.py`.

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186256

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
In Superset, the `dataset` object is typically accessed through the `DatasetDAO` class, which provides methods for interacting with datasets in the database. To retrieve a dataset object in `excel.py`, you can use the `get_dataset_by_id` method from `DatasetDAO`. Here's an example of how you might implement this:

1. **Import the necessary module**: Ensure you import the `DatasetDAO` class in your `excel.py` file.

```python
from superset.daos.dataset import DatasetDAO
```

2. **Retrieve the dataset object**: Use the `get_dataset_by_id` method to fetch the dataset object using its ID.

```python
def get_dataset_by_id(dataset_id: int):
    # Use DatasetDAO to retrieve the dataset object
    dataset = DatasetDAO.find_by_id(dataset_id)
    return dataset
```

3. **Access dataset properties**: Once you have the dataset object, you can access its properties, such as descriptions and columns.

```python
def get_dataset_description_and_columns(dataset_id: int):
    dataset = get_dataset_by_id(dataset_id)
    if not dataset:
        return None, None

    # Access dataset description
    dataset_description = dataset.description

    # Access column descriptions
    column_descriptions = {column.column_name: column.description for column in dataset.columns}

    return dataset_description, column_descriptions
```

This code provides a way to retrieve the dataset object and access its description and column metadata, which you can then use in your Excel export logic in `excel.py` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/daos/dataset.py)</sup>.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=2d271908-91fd-4c3e-b613-38e0ffb446c0) [![Learn about superset with Dosu](https://img.shields.io/badge/Learn%20about%20superset%20with%20Dosu-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS4yOTIzNiAxMi43OTI4TDE3Ljc1OTMgNi42ODE4OFY3Mi41NjY3TDUuMjkyMzYgODQuMDYxOFYxMi43OTI4WiIgZmlsbD0iI0I0QkI5MSIvPjxwYXRoIGQ9Ik0xOC4yNTc1IDczLjExOTZMNTkuMTMyOSA3Mi43NDhMNTEuNzAxMSA4Mi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QzM3LjEwOTMgNDkuNDczOCAzMi41Nzg3IDM3LjM1OTYgMzIuNTc4NyAzNi4wMTM1IiBzdHJva2U9ImJsYWNrIiB
 zdHJva2Utd2lkdGg9IjcuNjkxNjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0wLjM0ODYzMyA4NS40OTQ2QzAuMzQ4NjMzIDg1LjQ5NDYgMjkuNDg1NiA4NS44MzA5IDM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [![Add Dosu to your team](https://img.shields.io/badge/Add%20Dosu%20to%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186331

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
To retrieve the actual physical value of `dataset_id` for passing to the `df_to_excel` function when exporting chart data to Excel in Superset, you can use the `ChartDataRestApi._map_form_data_datasource_to_dataset_id` method. This method maps the form data's datasource to a dataset ID. Here's how you can use it:

```python
response = ChartDataRestApi._map_form_data_datasource_to_dataset_id(
    ChartDataRestApi, query_context_payload
)
dataset_id = response.get("dataset_id")
```

Ensure that your `query_context_payload` is correctly set up with the appropriate datasource information. This method will return a dictionary containing the `dataset_id` if available <sup>[[1]](https://github.com/apache/superset/blob/master/superset/jinja_context.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/tests/integration_tests/charts/data/api_tests.py)</sup>.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=dc9aacf4-f781-4ba9-bbc0-479688e565b2) [![Learn about superset with Dosu](https://img.shields.io/badge/Learn%20about%20superset%20with%20Dosu-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS4yOTIzNiAxMi43OTI4TDE3Ljc1OTMgNi42ODE4OFY3Mi41NjY3TDUuMjkyMzYgODQuMDYxOFYxMi43OTI4WiIgZmlsbD0iI0I0QkI5MSIvPjxwYXRoIGQ9Ik0xOC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MzYuMDEzNSA2NS43MzY5IDQ5LjQ3MzggNTEuNDIzMSA0OS40NzM4QzM3LjEwOTMgNDkuNDczOCAzMi41Nzg3IDM3LjM1OTYgMzIuNTc4NyAzNi4wMTM1IiBzdHJva2U9ImJsYWNrIiB
 zdHJva2Utd2lkdGg9IjcuNjkxNjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0wLjM0ODYzMyA4NS40OTQ2QzAuMzQ4NjMzIDg1LjQ5NDYgMjkuNDg1NiA4NS44MzA5IDM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [![Add Dosu to your team](https://img.shields.io/badge/Add%20Dosu%20to%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13189379

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil edited a discussion: Get dataset description and columns description

During the Excel export, I want to include dataset description and column descriptions.
I’d like to place them on a separate sheet in the output XLSX file.

From what I've found, I need to modify these two files:
1. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)/[core.py](https://github.com/apache/superset/tree/master/superset/utils/core.py)
2. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)/[excel.py](https://github.com/apache/superset/tree/master/superset/utils/excel.py)

However, I couldn’t find the description fields in core.py for either the dataset or its columns.
Could you suggest how to implement this? 

@dosu

GitHub link: https://github.com/apache/superset/discussions/33504

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil edited a discussion: Get dataset description and columns description

During the Excel export, I want to include dataset description and column descriptions.
I’d like to place them on a separate sheet in the output XLSX file.

From what I've found, I need to modify these two files:
1. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)
/core.py
2. [superset](https://github.com/apache/superset/tree/master/superset)/[utils](https://github.com/apache/superset/tree/master/superset/utils)
/excel.py

However, I couldn’t find the description fields in core.py for either the dataset or its columns.
Could you suggest how to implement this? 

@dosu

GitHub link: https://github.com/apache/superset/discussions/33504

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] added a comment to the discussion: Get dataset description and columns description

<!-- Answer -->
To retrieve the actual physical value of `dataset_id` for passing to the `df_to_excel` function when exporting chart data to Excel in Superset, you can use the `ChartDataRestApi._map_form_data_datasource_to_dataset_id` method. This method maps the form data's datasource to a dataset ID. Here's how you can use it:

```python
response = ChartDataRestApi._map_form_data_datasource_to_dataset_id(
    ChartDataRestApi, query_context_payload
)
dataset_id = response.get("dataset_id")
```

Ensure that your `query_context_payload` is correctly set up with the appropriate datasource information. This method will return a dictionary containing the `dataset_id` if available <sup>[[1]](https://github.com/apache/superset/blob/master/superset/jinja_context.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/tests/integration_tests/charts/data/api_tests.py)</sup>.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/dc9aacf4-f781-4ba9-bbc0-479688e565b2?feedback_type=other)</sup>


GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13189379

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil deleted a comment on the discussion: Get dataset description and columns description

How do I get `dataset_id`? 
How to modify `excel.py` to retrieve the dataset id exported to Excel? 

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186340

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "ampil (via GitHub)" <gi...@apache.org>.
GitHub user ampil added a comment to the discussion: Get dataset description and columns description

How do I get `dataset_id`? 
How to modify `excel.py` to retrieve the dataset id exported to Excel? 

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186340

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
To include dataset and column descriptions in the Excel export, you can follow these steps:

1. **Retrieve Descriptions**: First, ensure you have access to the dataset and column descriptions. These are defined in various parts of the Superset codebase, such as in the `superset/datasets/schemas.py` file and the frontend interface in `superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/schemas.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts)</sup>.

2. **Modify `core.py`**: Although `core.py` does not directly handle descriptions, you can use functions like `get_column_name` and `get_column_names` to retrieve column metadata. You might need to extend these functions or create new ones to fetch descriptions if they are not already included <sup>[[3]](https://github.com/apache/superset/blob/master/tests/unit_tests/core_tests.py)</sup>.

3. **Modify `excel.py`**: In `excel.py`, you can modify the `df_to_excel` function to add a new sheet for descriptions. Use the `xlsxwriter` library to create a workbook and add worksheets. Here's a basic example of how you can add a new sheet for descriptions:

```python
import io
import pandas as pd
import xlsxwriter

def df_to_excel_with_descriptions(df: pd.DataFrame, dataset_description: str, column_descriptions: dict, **kwargs: Any) -> Any:
    output = io.BytesIO()

    # Quote formulas to prevent malicious injections
    df = quote_formulas(df)

    with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
        # Write the main data to the first sheet
        df.to_excel(writer, sheet_name='Data', **kwargs)

        # Add a new sheet for descriptions
        workbook = writer.book
        description_sheet = workbook.add_worksheet('Descriptions')

        # Write dataset description
        description_sheet.write(0, 0, 'Dataset Description')
        description_sheet.write(0, 1, dataset_description)

        # Write column descriptions
        description_sheet.write(1, 0, 'Column Name')
        description_sheet.write(1, 1, 'Description')
        row = 2
        for column, description in column_descriptions.items():
            description_sheet.write(row, 0, column)
            description_sheet.write(row, 1, description)
            row += 1

    return output.getvalue()
```

In this example, `dataset_description` is a string containing the dataset's description, and `column_descriptions` is a dictionary where keys are column names and values are their descriptions. You will need to pass these to the function when calling it.

By implementing these changes, you can include the dataset and column descriptions in a separate sheet in the exported Excel file.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=6373ebbc-40a1-40ae-bd70-c40954a1cd48) [![Learn about superset with Dosu](https://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LjM4NDcgNzguNTU2IDM4LjM3MDFIOTIuNzUwNUM5Mi43NTA1IDEzLjU0NTMgNzIuNjI2IC02LjU3OTE5IDQ3LjgwMTMgLTYuNTc5MTlWNy42MTUzMlpNNDIuNTgwNSA3LjYxNTMySDQ3LjgwMTNWLTYuNTc5MTlINDIuNTgwNVY3LjYxNTMyWk00MC43MDQgNy42MTUzMkg0Mi41ODA1Vi02LjU3OTE5SDQwLjcwNFY3LjYxNTMyWiIgZmlsbD0iYmxhY2siIG1hc2s9InVybCgjZG9zdS1kLWN1dG91dCkiLz48cGF0aCBkPSJNNjguOTIxNSAzNi4wMTM1QzY4LjkyMTUgMzYuMDEzNSA2NS43MzY5IDQ5LjQ3MzggNTEuNDIzMSA0OS40NzM4QzM3LjEwOTMgNDkuNDczOCAzMi41Nzg3IDM3LjM1OTYgMzIuNTc4NyAzNi4wMTM1IiBzdHJva2U9ImJsYWNrIiB
 zdHJva2Utd2lkdGg9IjcuNjkxNjEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0wLjM0ODYzMyA4NS40OTQ2QzAuMzQ4NjMzIDg1LjQ5NDYgMjkuNDg1NiA4NS44MzA5IDM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [![Add Dosu to your team](https://img.shields.io/badge/Add%20Dosu%20to%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186210

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [D] Get dataset description and columns description [superset]

Posted by "dosubot[bot] (via GitHub)" <gi...@apache.org>.
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description

<!-- Answer -->
To modify the `superset/datasets/schemas.py` and `core.py` files to read `dataset_description` and `column_descriptions` for use in `excel.py`, follow these steps:

1. **Modify `superset/datasets/schemas.py`**: Ensure that the dataset and column descriptions are accessible. This file already includes schema classes with description fields, so you might not need to modify it directly. However, ensure that these fields are being populated correctly when datasets and columns are created or updated.

2. **Modify `core.py`**: You need to create functions to retrieve the dataset and column descriptions. Here's a basic example of how you might implement these functions:

```python
def get_dataset_description(dataset_id: int) -> str:
    # Fetch the dataset description from the database using the dataset_id
    # This is a placeholder implementation; replace it with actual database access logic
    dataset = get_dataset_by_id(dataset_id)  # Assume this function fetches the dataset object
    return dataset.description if dataset else ""

def get_column_descriptions(dataset_id: int) -> dict:
    # Fetch column descriptions for a given dataset_id
    # This is a placeholder implementation; replace it with actual database access logic
    dataset = get_dataset_by_id(dataset_id)  # Assume this function fetches the dataset object
    if not dataset:
        return {}

    column_descriptions = {}
    for column in dataset.columns:
        column_descriptions[column.name] = column.description

    return column_descriptions
```

3. **Integrate with `excel.py`**: Use these functions to retrieve descriptions and pass them to the `df_to_excel_with_descriptions` function. Here's how you might call these functions and use them in `excel.py`:

```python
def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve descriptions
    dataset_description = get_dataset_description(dataset_id)
    column_descriptions = get_column_descriptions(dataset_id)

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, column_descriptions, **kwargs)
```

Ensure that you replace the placeholder logic in `get_dataset_description` and `get_column_descriptions` with actual database queries or ORM calls to fetch the dataset and column descriptions from your data source.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*

---

Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).

[![Leave Feedback](https://img.shields.io/badge/Leave%20Feedback-555555?style=flat)](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=2ef4b63e-2fa0-4607-b72d-b6fcdbea1762) [![Learn about superset with Dosu](https://img.shields.io/badge/Learn%20about%20superset%20with%20Dosu-2f7b3f?style=flat&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iODYiIGhlaWdodD0iODkiIHZpZXdCb3g9IjAgMCA4NiA4OSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNS4yOTIzNiAxMi43OTI4TDE3Ljc1OTMgNi42ODE4OFY3Mi41NjY3TDUuMjkyMzYgODQuMDYxOFYxMi43OTI4WiIgZmlsbD0iI0I0QkI5MSIvPjxwYXRoIGQ9Ik0xOC4yNTc1IDczLjExOTZMNTkuMTMyOSA3Mi43NDhMNTEuNzAxMSA4Mi40MDk1TDI5LjAzMzggODYuMjkxTDYuMjM5NjIgODUuMTU1NEwxOC4yNTc1IDczLjExOTZaIiBmaWxsPSIjNzc4NTYxIi8%2BPHBhdGggZD0iTTE3LjQ5MT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jEiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjxwYXRoIGQ9Ik0wLjM0ODYzMyA4NS40OTQ2QzAuMzQ4NjMzIDg1LjQ5NDYgMjkuNDg1NiA4NS44MzA5IDM0LjgwOSA4NS42OThDNDQuODMzNyA4NS40NDc3IDUxLjI4NzIgODQuNDAyIDU3LjUyNjkgNzguOTcyNEM2Mi44MTI5IDc0LjM3MjcgNzUuMTM0MiA1OS42ODM2IDc1LjEzNDIgNTkuNjgzNiIgc3Ryb2tlPSJibGFjayIgc3Ryb2tlLXdpZHRoPSI2LjE2NDgyIi8%2BPC9zdmc%2B)](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [![Add Dosu to your team](https://img.shields.io/badge/Add%20Dosu%20to%20your%20team-1f6feb?style=flat)](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)

GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186262

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org