korbit-ai[bot] commented on code in PR #32696:
URL: https://github.com/apache/superset/pull/32696#discussion_r1997828043
##########
superset/databases/schemas.py:
##########
@@ -1086,7 +1086,10 @@ class BaseUploadFilePostSchemaMixin(Schema):
def validate_file_extension(self, file: FileStorage) -> None:
allowed_extensions = current_app.config["ALLOWED_EXTENSIONS"]
file_suffix = Path(file.filename).suffix
- if not file_suffix or file_suffix[1:] not in allowed_extensions:
+ if not file_suffix:
+ raise ValidationError([_("File extension is not allowed.")])
Review Comment:
### Misleading Error Message for Missing Extension <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The error message is misleading as it states the extension is not allowed
when in fact there is no extension at all.
###### Why this matters
Users receiving this error won't understand that they need to provide a file
with an extension rather than thinking their file extension is blocked.
###### Suggested change ∙ *Feature Preview*
```python
if not file_suffix:
raise ValidationError([_("File must have an extension.")])
```
</details>
<sub>
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/f23eed5a-5374-476e-81b0-6a006d763608?suggestedFixEnabled=true)
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:f0d3a435-0250-4c61-ab9a-fcb8e47f2438 -->
##########
superset-frontend/src/features/databases/UploadDataModel/index.tsx:
##########
@@ -183,8 +183,9 @@ export const validateUploadFileExtension = (
return false;
}
- const fileType = extensionMatch[1];
- return allowedExtensions.includes(fileType);
+ const fileType = extensionMatch[1].toLowerCase();
+ const lowerCaseAllowedExtensions = allowedExtensions.map(ext =>
ext.toLowerCase());
Review Comment:
### Unnecessary intermediate variable <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The variable name 'lowerCaseAllowedExtensions' is redundant with the
operation being performed. Since it's a one-time use variable that clearly
shows its transformation, an inline transformation would be more readable.
###### Why this matters
Creating intermediate variables that don't add semantic meaning increases
cognitive load when reading the code.
###### Suggested change ∙ *Feature Preview*
```typescript
return allowedExtensions.map(ext => ext.toLowerCase()).includes(fileType);
```
</details>
<sub>
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/eaa8ba28-8621-4288-aa2c-0f7e14f3eac5?suggestedFixEnabled=true)
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:987d0bf6-bd07-499e-bd8c-5801cc563c31 -->
--
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]