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 [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to