Skip to content

issue_1671 the first attempt is to capture the sql error and display the error in grade distribution view UI#1674

Open
zqian wants to merge 2 commits intotl-its-umich-edu:masterfrom
zqian:issue_1671
Open

issue_1671 the first attempt is to capture the sql error and display the error in grade distribution view UI#1674
zqian wants to merge 2 commits intotl-its-umich-edu:masterfrom
zqian:issue_1671

Conversation

@zqian
Copy link
Copy Markdown
Member

@zqian zqian commented Sep 16, 2025

Without change to the SQL code, the PR logs the sql error and also displays it in the grade distribution view UI.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 16, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jonespm jonespm requested a review from Copilot January 20, 2026 20:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds error handling to the grade distribution view to catch and display SQL errors instead of silently failing. When a SQLAlchemy error occurs during grade distribution query execution, the error is now logged and returned to the UI with a user-friendly message.

Changes:

  • Added SQLAlchemy error handling with try-except block around the grade distribution SQL query
  • Added logging for both successful query parameters and SQL errors
  • Returns JSON error response to UI when SQL errors occur

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dashboard/views.py
'enrollment_type': 'StudentEnrollment'
})
except SQLAlchemyError as e:
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user} enrollment_type=StudentEnrollment'
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

Missing comma between '{current_user}' and 'enrollment_type'. Should be 'current_user={current_user}, enrollment_type=StudentEnrollment'.

Suggested change
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user} enrollment_type=StudentEnrollment'
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user}, enrollment_type=StudentEnrollment'

Copilot uses AI. Check for mistakes.
Comment thread dashboard/views.py
except SQLAlchemyError as e:
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user} enrollment_type=StudentEnrollment'
logger.error(f"{grade_distribution_sql_error_msg} sql={grade_score_sql} error={e}")
return HttpResponse(json.dumps({'gd_disable':'true','gd_msg': grade_distribution_sql_error_msg}), content_type='application/json')
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

Use JsonResponse instead of manually constructing JSON with HttpResponse and json.dumps. This provides better consistency with Django conventions and automatically sets the content type.

Copilot uses AI. Check for mistakes.
Comment thread dashboard/views.py
except SQLAlchemyError as e:
grade_distribution_sql_error_msg = f'Error running grade distribution sql with course_id={course_id}, current_user={current_user} enrollment_type=StudentEnrollment'
logger.error(f"{grade_distribution_sql_error_msg} sql={grade_score_sql} error={e}")
return HttpResponse(json.dumps({'gd_disable':'true','gd_msg': grade_distribution_sql_error_msg}), content_type='application/json')
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The boolean value 'true' is returned as a string. Consider using a boolean type (True) in the dictionary for consistency, as json.dumps will correctly serialize it to the JSON boolean 'true'.

Copilot uses AI. Check for mistakes.
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.

Improve subselect in grade_distribution query to be more resilient to duplicate values

2 participants