Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1493 ruff format #1498

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open

1493 ruff format #1498

wants to merge 2 commits into from

Conversation

kastger
Copy link
Contributor

@kastger kastger commented Mar 12, 2025

Separate PR to clean code with two ruff commands:

  • poetry run ruff format .
  • poetry run ruff check . --fix

@kastger kastger self-assigned this Mar 12, 2025
@kastger kastger linked an issue Mar 12, 2025 that may be closed by this pull request
if file:
try:
validate_file(file)
except ValidationError as e:
raise serializers.ValidationError({'file': e})
raise serializers.ValidationError({"file": e})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI about 17 hours ago

To fix the problem, we should modify the code to log the detailed exception information on the server and return a generic error message to the user. This approach ensures that sensitive information is not exposed to the end user while still allowing developers to access the detailed error information for debugging purposes.

  1. Import the logging module to log the exception details.
  2. Replace the direct use of the exception e in the serializers.ValidationError with a generic error message.
  3. Log the detailed exception information using the logging module.
Suggested changeset 1
vitrina/api/serializers.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/vitrina/api/serializers.py b/vitrina/api/serializers.py
--- a/vitrina/api/serializers.py
+++ b/vitrina/api/serializers.py
@@ -16,2 +16,3 @@
 from vitrina.tasks.models import Task
+import logging
 
@@ -590,3 +591,4 @@
             except ValidationError as e:
-                raise serializers.ValidationError({"file": e})
+                logging.error("Validation error occurred: %s", e)
+                raise serializers.ValidationError({"file": _("An error occurred while validating the file.")})
         if file and url:
EOF
@@ -16,2 +16,3 @@
from vitrina.tasks.models import Task
import logging

@@ -590,3 +591,4 @@
except ValidationError as e:
raise serializers.ValidationError({"file": e})
logging.error("Validation error occurred: %s", e)
raise serializers.ValidationError({"file": _("An error occurred while validating the file.")})
if file and url:
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
if file:
try:
validate_file(file)
except ValidationError as e:
raise serializers.ValidationError({'file': e})
raise serializers.ValidationError({"file": e})

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI about 17 hours ago

To fix the problem, we should ensure that the exception message does not expose sensitive information to the end user. Instead of passing the exception e directly, we can log the detailed exception on the server and return a generic error message to the user.

  • Modify the validate method in the PostDatasetStructureSerializer class to log the exception and raise a generic error message.
  • Add necessary imports for logging if not already present.
Suggested changeset 1
vitrina/api/serializers.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/vitrina/api/serializers.py b/vitrina/api/serializers.py
--- a/vitrina/api/serializers.py
+++ b/vitrina/api/serializers.py
@@ -672,3 +672,8 @@
             except ValidationError as e:
-                raise serializers.ValidationError({"file": e})
+                # Log the detailed exception
+                import logging
+                logger = logging.getLogger(__name__)
+                logger.error("File validation error: %s", e)
+                # Raise a generic error message
+                raise serializers.ValidationError({"file": _("Invalid file format.")})
         return data
EOF
@@ -672,3 +672,8 @@
except ValidationError as e:
raise serializers.ValidationError({"file": e})
# Log the detailed exception
import logging
logger = logging.getLogger(__name__)
logger.error("File validation error: %s", e)
# Raise a generic error message
raise serializers.ValidationError({"file": _("Invalid file format.")})
return data
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@kastger kastger marked this pull request as ready for review March 12, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format code with ruff.
2 participants