korbit-ai[bot] commented on code in PR #35543:
URL: https://github.com/apache/superset/pull/35543#discussion_r2410480091
##########
superset/commands/dataset/update.py:
##########
@@ -166,6 +167,24 @@ def _validate_dataset_source(self, exceptions:
list[ValidationError]) -> None:
):
exceptions.append(DatasetExistsValidationError(table))
+ if sql := self._properties.get("sql"):
+ try:
+ security_manager.raise_for_access(
+ database=db,
+ sql=sql,
+ catalog=catalog,
+ schema=schema,
+ )
+ except SupersetSecurityException as ex:
+
exceptions.append(DatasetDataAccessIsNotAllowed(ex.error.message))
+ except SupersetParseError as ex:
+ exceptions.append(
+ ValidationError(
+ f"Invalid SQL: {ex.error.message}",
+ field_name="sql",
+ )
+ )
Review Comment:
### Unnecessary SQL validation on unchanged SQL <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
SQL validation is performed on every dataset update even when SQL hasn't
changed, causing unnecessary parsing and security checks.
###### Why this matters
This leads to redundant computational overhead during dataset updates,
especially for large SQL queries or frequent updates where the SQL remains
unchanged.
###### Suggested change ∙ *Feature Preview*
Only perform SQL validation when the SQL has actually changed by comparing
against the existing model's SQL:
```python
if sql := self._properties.get("sql"):
# Only validate if SQL is different from current model
if sql != self._model.sql:
try:
security_manager.raise_for_access(
database=db,
sql=sql,
catalog=catalog,
schema=schema,
)
except SupersetSecurityException as ex:
exceptions.append(DatasetDataAccessIsNotAllowed(ex.error.message))
except SupersetParseError as ex:
exceptions.append(
ValidationError(
f"Invalid SQL: {ex.error.message}",
field_name="sql",
)
)
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/82af4460-75f6-4a2a-8733-7f2d61ad3cc7/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/82af4460-75f6-4a2a-8733-7f2d61ad3cc7?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/82af4460-75f6-4a2a-8733-7f2d61ad3cc7?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/82af4460-75f6-4a2a-8733-7f2d61ad3cc7?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/82af4460-75f6-4a2a-8733-7f2d61ad3cc7)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:a827f317-ad57-46f5-8583-f4fe29d261bf -->
[](a827f317-ad57-46f5-8583-f4fe29d261bf)
--
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]