Skip to content

Fix TypeError when the answer or response is an inequality - #297

Merged
m-messer merged 1 commit into
mainfrom
fix/check-equality-typeerror
Oct 23, 2026
Merged

m-messer merged 1 commit into
mainfrom
fix/check-equality-typeerror

Conversation

@m-messer

Copy link
Copy Markdown
Member

Problem

The evaluation logging from #294 showed 8 TypeError failures in production in 24 hours (22–23 Oct), all in generate_feedback at check_equality (app/context/symbolic.py). check_equality subtracts the two sides (lhs_expr-rhs_expr), which raises a TypeError when either side is an inequality or a boolean. There were two causes:

  • Inequality in the response (4 cases): numeric answers in draw mode where the recognised response was an inequality, e.g. 8<9 against an answer of 8.
  • Inequality in the answer (4 cases): an answer of 5<1.43, which fails for every response.

The user docs don't advertise inequalities as answers or responses (an EXPRESSION has no =, <, >). Full support is added by #276, which is being ported onto the refactor. This PR is a hotfix that stops the crash on main until then.

Changes

  • app/context/symbolic.py: new is_inequality_or_boolean helper (Relational or BooleanAtom, but not Equality). check_equality returns False when either side matches, in the same way as the existing guard for a lone Equality. It doesn't check for Boolean, because sympy's Symbol is a subclass of Boolean.
  • app/evaluation.py: parse_reserved_expressions raises a TaskConfigurationError (RESERVED_EXPRESSION_INEQUALITY_answer) when a task expression is an inequality or a boolean. The teacher then sees a configuration error, instead of every student being marked incorrect. The message only contains the label, so no user data is logged.
  • app/tests/symbolic_evaluation_test.py: regression tests for both cases.

Not changed: check_order (criteria like response > answer) has the same unguarded subtraction. It didn't appear in the logs.

Checklist

  • Tests added/updated. Full suite: 3146 passed, 4 skipped. Without the fix, 5 of the 6 new cases fail.
  • Docs updated (app/docs.md) if user-facing behaviour changed. Not needed, since inequalities were never documented as supported.

🤖 Generated with Claude Code

check_equality subtracted the two sides, which raises a TypeError for
inequalities and booleans (e.g. a response of 8<9, or an answer of 5<1.43,
which evaluates to False). Inequalities are not supported yet, so:

- an inequality in the response is marked incorrect
- an inequality in the answer raises a TaskConfigurationError

Full inequality support is added by #276.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-messer
m-messer merged commit 94f4fea into main Oct 23, 2026
10 checks passed
@m-messer
m-messer deleted the fix/check-equality-typeerror branch October 23, 2026 14:32
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.

1 participant