Abdulrehman-PIAIC80387 opened a new pull request, #40494:
URL: https://github.com/apache/superset/pull/40494
### SUMMARY
Fixes #30377. Adopts the approach from the stale PR #30379 by @luizcapu
(credited below).
`POST /api/v1/dataset/get_or_create/` accepts a `schema` field in the
request body but ignores it during the existence check, calling
`DatasetDAO.get_table_by_name(database_id, table_name)`. This produces two
failures:
- **500 (MultipleResultsFound)** — when two or more datasets already exist
with the same `table_name` across different schemas, `one_or_none()` raises.
- **False-positive 200** — when one dataset exists in schema A and the
caller asks for the same `table_name` in schema B, the API returns the schema-A
dataset and never creates the schema-B one.
The mismatch is invisible in default deployments because most installs only
ever have one dataset per `table_name`.
### Fix
- Adds `DatasetDAO.get_table_by_schema_and_name(database_id, schema,
table_name)`.
- `get_or_create_dataset` now reads `body.get("schema")` and uses the
schema-aware lookup, matching the contract the request schema already
advertises.
### TESTING INSTRUCTIONS
```bash
pytest
tests/integration_tests/datasets/api_tests.py::DatasetApiTests::test_get_or_create_dataset_disambiguates_by_schema
-v
```
Regression test seeds two datasets with the same `table_name` in different
schemas, then asserts both lookups (`schema=schema_a` and `schema=schema_b`)
return the correct dataset id without raising.
### Credit
This PR adopts the approach from #30379 by @luizcapu (Pinterest), which sat
without review for ~1 year. @rusackas invited adoption on the issue thread
three times in 2025-2026. I left a courtesy ping on the issue and proceeded.
Modern union syntax (`str | None`) is used throughout; the original PR's
`Optional[str]` reverts are not included per Superset's Python style.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #30377
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]