Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion web/quiz_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import random

from django.contrib import messages
Expand All @@ -19,6 +20,8 @@
)
from .models import Quiz, QuizQuestion, UserQuiz

logger = logging.getLogger(__name__)


@login_required
def quiz_list(request):
Expand Down Expand Up @@ -182,7 +185,7 @@ def add_question(request, quiz_id):
else:
return redirect("quiz_detail", quiz_id=quiz.id)
except Exception as e:
print(e)
logger.exception("Error adding question to quiz")
# Re-raise the exception
raise
Comment on lines 187 to 190
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Good switch to structured logging! Minor cleanup: remove unused variable e.

The change from print(e) to logger.exception() is excellent—logger.exception() automatically captures the full traceback from the current exception context, so there's no need to reference e at all.

Since e is now unused, consider simplifying to except Exception: to avoid potential linter warnings (flake8 F841).

🧹 Suggested cleanup
-            except Exception as e:
+            except Exception:
                 logger.exception("Error adding question to quiz")
                 # Re-raise the exception
                 raise
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except Exception as e:
print(e)
logger.exception("Error adding question to quiz")
# Re-raise the exception
raise
except Exception:
logger.exception("Error adding question to quiz")
# Re-raise the exception
raise
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/quiz_views.py` around lines 187 - 190, The except block currently binds
an unused variable (`except Exception as e:`) even though logger.exception()
uses the exception context; change the handler to `except Exception:` in the
same block where logger.exception("Error adding question to quiz") and the
subsequent re-raise occur (look for the except around logger.exception in
quiz_views.py) to remove the unused `e` and avoid linter warning F841.

else:
Expand Down
1 change: 0 additions & 1 deletion web/recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,3 @@ def get_similar_courses(course, limit=3):
)

return similar_courses[:limit]
return similar_courses[:limit]
Loading