Skip to content

feat: add SQL Grader XBlock#18

Merged
irtazaakram merged 8 commits intomainfrom
add-xblock-sql-grader
Apr 15, 2026
Merged

feat: add SQL Grader XBlock#18
irtazaakram merged 8 commits intomainfrom
add-xblock-sql-grader

Conversation

@irtazaakram
Copy link
Copy Markdown
Member

@irtazaakram irtazaakram commented Apr 8, 2026

This PR moved SQL grader XBlock from https://github.com/openedx/xblock-sql-grader

Fix: codejail-service REST API support

The original code called codejail.safe_exec() directly, which crashes on Tutor deployments with FileNotFoundError: 'TMPDIR=tmp'. Tutor sets ENABLE_CODEJAIL_REST_SERVICE=True and disables the local sandbox, routing all execution through the codejail-service container instead. See openedx/openedx-platform#36639

Testing

Tested end-to-end on Tutor local with tutor-contrib-codejail (v2 mode, openedx/codejail-service, Python 3.12). xblocks-extra was pip-installed in the sandbox venv via CODEJAIL_EXTRA_PIP_REQUIREMENTS.

  tutor config save \
    --set CODEJAIL_USE_SERVICE_V2=true \
    --set CODEJAIL_SERVICE_V2_VERSION=main \
    --set CODEJAIL_SANDBOX_PYTHON_VERSION=3.12.12 \
    --set "CODEJAIL_EXTRA_PIP_REQUIREMENTS=[\"git+https://github.com/openedx/xblocks-extra.git@add-xblock-sql-grader#egg=xblocks-extra\"]"

  CODEJAIL_DF="$TUTOR_ROOT/env/plugins/codejail/build/codejail-service/Dockerfile"
  sed -i "" "s/    sudo  \\\\/    git \\\\\n    sudo  \\\\/" "$CODEJAIL_DF"
  sed -i "" "s/^ARG SANDBOX_DEPS_VERSION=main$/ARG SANDBOX_DEPS_VERSION=master/" "$CODEJAIL_DF"

Confirmed via codejail-service logs that requests reach the container:

[2026-04-15 06:53:15 +0000] [7] [INFO] POST /api/v0/code-exec

2026-04-15 06:53:15,429 INFO 7 [codejail] [user None] [ip None] jail_code.py:303 - Preparing to execute jailed code 'sql_grader' (overrides context = None, resource limits = {'CPU': 3, 'REALTIME': 3, 'VMEM': 536870912, 'FSIZE': 10485760, 'NPROC': 15, 'PROXY': 0}).

2026-04-15 06:53:15,431 INFO 7 [codejail] [user None] [ip None] subproc.py:47 - Executed jailed code sql_grader in /tmp/codejail-qtkbllzr, with PID 59
Screenshot 2026-04-15 at 11 50 51 AM Screenshot 2026-04-15 at 11 51 14 AM Screenshot 2026-04-15 at 11 52 26 AM Screenshot 2026-04-15 at 11 52 41 AM

The original repository is being deprecated here: openedx/xblock-sql-grader#255

@irtazaakram irtazaakram force-pushed the add-xblock-sql-grader branch from 3bdc732 to e4c187d Compare April 9, 2026 12:32
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 86.98885% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.98%. Comparing base (d4ad4ac) to head (1491413).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
src/sql_grader/mixins/grading.py 80.26% 14 Missing and 1 partial ⚠️
src/sql_grader/problem.py 90.47% 8 Missing and 2 partials ⚠️
src/sql_grader/xblocks.py 86.66% 4 Missing ⚠️
src/sql_grader/__init__.py 50.00% 2 Missing ⚠️
src/sql_grader/mixins/fragment.py 93.93% 1 Missing and 1 partial ⚠️
src/sql_grader/mixins/scenario.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #18      +/-   ##
==========================================
+ Coverage   79.69%   86.98%   +7.29%     
==========================================
  Files          30        7      -23     
  Lines         778      269     -509     
  Branches       50       23      -27     
==========================================
- Hits          620      234     -386     
+ Misses        136       31     -105     
+ Partials       22        4      -18     
Flag Coverage Δ
unittests 86.98% <86.98%> (+7.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@irtazaakram irtazaakram marked this pull request as ready for review April 14, 2026 19:56
log = logging.getLogger("sql_grader")


def _send_to_codejailservice(code, globals_dict, slug=None):
Copy link
Copy Markdown
Member Author

@irtazaakram irtazaakram Apr 15, 2026

Choose a reason for hiding this comment

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

Added _send_to_codejailservice() which sends code to the codejail-service REST API (/api/v0/code-exec), mirroring the protocol used by the problem XBlock in xblocks_contrib.problem.capa.safe_exec.remote_exec

Modified attempt_safe() to route based on ENABLE_CODEJAIL_REST_SERVICE:
- True → REST API (Tutor / production)
- False → local safe_exec (native installs, unchanged behaviour)

No python_path is sent to the REST API because sql_grader is pip-installed in the sandbox venv at image build time.

This function _send_to_codejailservice was generated with the help of Claude code,

@irtazaakram irtazaakram requested review from farhan, feanil and salman2013 and removed request for farhan and feanil April 15, 2026 07:15
@irtazaakram irtazaakram self-assigned this Apr 15, 2026
Copy link
Copy Markdown
Contributor

@farhan farhan left a comment

Choose a reason for hiding this comment

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

Good work!

@irtazaakram irtazaakram merged commit 2f72077 into main Apr 15, 2026
7 checks passed
@irtazaakram irtazaakram deleted the add-xblock-sql-grader branch April 15, 2026 19:35
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.

XBlock SQL Grader Migration

2 participants