You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "sadpandajoe (via GitHub)" <gi...@apache.org> on 2026/02/19 02:57:46 UTC
[PR] fix(reports): validate database field on PUT report schedule [superset]
sadpandajoe opened a new pull request, #38084:
URL: https://github.com/apache/superset/pull/38084
### SUMMARY
`PUT /api/v1/report/{id}` with `{"database": N}` on a Report-type schedule returned **500 Internal Server Error** instead of a validation error. The POST endpoint correctly rejects this at the schema level (400), but the PUT path had no equivalent check.
**Root cause:** `ReportSchedulePutSchema` lacks the `@validates_schema` cross-validation that `ReportSchedulePostSchema` has (`validate_report_references`). For PUT with partial updates, the schema can't reliably perform this check because `type` may be absent from the payload. The fix adds command-level validation in `UpdateReportScheduleCommand.validate()`.
**Changes:**
- Add `ReportScheduleDatabaseNotAllowedValidationError` exception class
- Add command-level validation enforcing both invariants:
- **Reports must not have a database** — rejects database in payload or on model
- **Alerts must have a database** — rejects null/missing database in payload and on model
- Add `allow_none=True` on `ReportSchedulePutSchema.database` to allow clearing via `{"database": null}` (consistent with the `dashboard` field)
- Change DB existence check from truthiness to explicit `database_id is not None`
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
**Before:**
```
PUT /api/v1/report/23 {"database": 1} → 500 Internal Server Error
```
**After:**
```
PUT /api/v1/report/23 {"database": 1} → 422 {"message": {"database": "Database reference is not allowed on a report"}}
```
### TESTING INSTRUCTIONS
1. Create an Alert with a database and a Report without one
2. `PUT /api/v1/report/{report_id}` with `{"database": <valid_id>}` → should return **422**
3. `PUT /api/v1/report/{alert_id}` with `{"database": null}` → should return **422**
4. `PUT /api/v1/report/{alert_id}` with `{"type": "Report", "database": null}` → should return **200** (valid transition)
5. `PUT /api/v1/report/{report_id}` with `{"type": "Alert"}` (no database) → should return **422**
6. `PUT /api/v1/report/{report_id}` with `{"type": "Alert", "database": <valid_id>}` → should return **200**
**Automated tests:**
- 7 new integration test methods covering all type/database combinations and transitions
- 12 new unit tests for `UpdateReportScheduleCommand.validate()` covering the full payload × model matrix
- 2 existing tests updated for new validation constraints
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #38084:
URL: https://github.com/apache/superset/pull/38084#issuecomment-3924408860
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | e6fa96878ef6b396fc2b606141e919952a9c98d7 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/69967c2a6137b6000836ca87 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-38084--superset-docs-preview.netlify.app](https://deploy-preview-38084--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-38084--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #38084:
URL: https://github.com/apache/superset/pull/38084#discussion_r2829208948
##########
tests/unit_tests/commands/report/update_test.py:
##########
@@ -0,0 +1,234 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Unit tests for UpdateReportScheduleCommand.validate() database invariants."""
+
+from __future__ import annotations
+
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.commands.report.exceptions import (
+ ReportScheduleInvalidError,
+)
+from superset.commands.report.update import UpdateReportScheduleCommand
+from superset.reports.models import ReportScheduleType
+
+
+def _make_model(
+ mocker: MockerFixture,
+ *,
+ model_type: str,
+ database_id: int | None,
+) -> MagicMock:
Review Comment:
Type annotations in `_make_model` don’t match what’s actually returned/used: `mocker.Mock()` returns a `unittest.mock.Mock` (not `MagicMock`), and callers pass `ReportScheduleType` values (a `StrEnum`), not `str`. Align the annotations (e.g., return `Mock` and accept `ReportScheduleType | str`) to avoid misleading type checking.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38084:
URL: https://github.com/apache/superset/pull/38084#issuecomment-3947680936
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #38084:
URL: https://github.com/apache/superset/pull/38084#discussion_r2843262991
##########
tests/unit_tests/commands/report/update_test.py:
##########
@@ -0,0 +1,234 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Unit tests for UpdateReportScheduleCommand.validate() database invariants."""
+
+from __future__ import annotations
+
+from unittest.mock import MagicMock
+
+import pytest
+from pytest_mock import MockerFixture
+
+from superset.commands.report.exceptions import (
+ ReportScheduleInvalidError,
+)
+from superset.commands.report.update import UpdateReportScheduleCommand
+from superset.reports.models import ReportScheduleType
+
+
+def _make_model(
+ mocker: MockerFixture,
+ *,
+ model_type: str,
+ database_id: int | None,
+) -> MagicMock:
Review Comment:
Fixed in cb6a499 — updated return type to `Mock` and parameter to `ReportScheduleType | str`.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38084:
URL: https://github.com/apache/superset/pull/38084#issuecomment-3928788359
<!-- Bito Reply -->
Yes, the suggestion is valid — updating the return type to `Mock` accurately reflects what `mocker.Mock()` returns, and changing the parameter to `ReportScheduleType | str` matches the enum values passed in tests while maintaining flexibility.
**tests/unit_tests/commands/report/update_test.py**
```
def _make_model(
mocker: MockerFixture,
*,
model_type: ReportScheduleType | str,
database_id: int | None,
) -> Mock:
model = mocker.Mock()
model.type = model_type
model.database_id = database_id
model.name = "test_schedule"
model.crontab = "0 9 * * *"
model.last_state = "noop"
model.owners = []
return model
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #38084:
URL: https://github.com/apache/superset/pull/38084#issuecomment-3924396542
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(reports): validate database field on PUT report schedule [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe merged PR #38084:
URL: https://github.com/apache/superset/pull/38084
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org