dosubot[bot] commented on issue #33659:
URL: https://github.com/apache/superset/issues/33659#issuecomment-2933293338

   <!-- Answer -->
   To fetch dataset UUIDs by passing a database name in Superset, you need to 
follow a two-step process using the backend logic:
   
   1. Use the `get_database_by_name` method from the `DatabaseDAO` class to 
retrieve the database object by its name. This gives you the database ID.
   2. Use the `get_datasets` method from the same class to fetch all datasets 
for that database ID. Each dataset object will have a `uuid` attribute.
   
   Here’s a Python-style pseudocode example that demonstrates this approach:
   
   ```python
   from superset.daos.database import DatabaseDAO
   
   # Step 1: Get the database object by name
   database = DatabaseDAO.get_database_by_name("your_database_name")
   if not database:
       print("Database not found")
   else:
       # Step 2: Get all datasets for this database
       datasets = DatabaseDAO.get_datasets(database.id, catalog=None, 
schema=None)
       # Extract UUIDs
       dataset_uuids = [ds.uuid for ds in datasets]
       print(dataset_uuids)
   ```
   
   This approach allows you to check which datasets (and their UUIDs) exist for 
a given database name, which is useful for verifying dataset availability 
during chart migration between Superset instances. There is no single API 
endpoint that directly returns dataset UUIDs by database name, but this method 
reliably composes the necessary backend calls to achieve your goal. For more 
details, see the relevant code in 
[superset/daos/database.py](https://github.com/apache/superset/blob/fc13a0fde5b775f6734a0280742f44ddc2acdadb/superset/daos/database.py)
 and 
[superset/datasets/api.py](https://github.com/apache/superset/blob/fc13a0fde5b775f6734a0280742f44ddc2acdadb/superset/datasets/api.py).
   
   If you need to do this via the Superset REST API, you can use the 
`/api/v1/dataset/` endpoint with query parameters to filter by database ID, 
which you can obtain by first querying 
`/api/v1/database/?q=(filters:!((col:database_name,opr:eq,value:'your_database_name')))`.
 Then, use the database ID to filter datasets and extract their UUIDs from the 
response.
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/a8369d95-5bb1-4524-a087-72e63fabb61d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[!
 [Share on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/33659)


-- 
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]

Reply via email to