-
Notifications
You must be signed in to change notification settings - Fork 279
Description
TypeError in Twig printtimediff Filter When Judging Has No Start Time
Problem Description
The application throws a TypeError when rendering the jury judgehost judgings page if a judging exists that has not yet started (i.e., starttime is null).
Error Message
An exception has been thrown during the rendering of a template
("App\Twig\TwigExtension::printtimediff(): Argument #1 ($start) must be of type float, null given,
called in /home/maratona/public_html/domserver/webapp/var/cache/prod/twig/02/020d3a6fb687b4fc640c9f707f687a20.php
at line 103") in "jury/partials/judgehost_judgings.html.twig" at line 26.
Root Cause
The printtimediff Twig filter in has a strict type declaration that requires the first parameter $start to be a float: TwigExtension.php
public function printtimediff(float $start, ?float $end = null): string { return Utils::printtimediff($start, $end); }
However, when a judging is created but not yet assigned to a judgehost, the starttime field remains null. When the template attempts to call {{ judging.starttime|printtimediff }}, it passes null as the first argument, violating the type constraint and causing a TypeError.
When This Occurs
This bug manifests in the following scenarios:
- Newly Created Judgings: When a submission is judged but no judgehost has claimed the judging yet
- Queued Judgings: Judgings waiting in the queue for an available judgehost
- After Migration: When migrating from older DOMjudge versions with incomplete judgings
- Internal Errors: When judgings are created but immediately encounter errors before starting
- Judgehost Restarts: When judgings are given back to the queue and lose their start time
Impact
- Jury interface crashes when viewing judgehost details with pending judgings
- Monitoring pages become inaccessible
- System appears broken even though the judging system itself is functioning
- No workaround available without database manipulation
Expected Behavior
The printtimediff filter should gracefully handle null start times by displaying a placeholder value (such as "-" or "not started") instead of throwing a TypeError.
Proposed Solution
Modify the printtimediff method in to accept null as the first parameter and handle it appropriately: TwigExtension.php
public function printtimediff(?float $start, ?float $end = null): string { if ($start === null) { return '-'; } return Utils::printtimediff($start, $end); }
Why This Solution Is Correct
- Defensive Programming: Handles edge cases where timing information is incomplete
- User-Friendly: Displays meaningful placeholder instead of crashing
- Consistent: Matches the pattern used elsewhere in the codebase for displaying null values
- Minimal Change: Simple one-line fix that doesn't affect existing functionality
- Type Safe: Maintains type safety while being more permissive about input
Testing Recommendations
- Create a submission and immediately view the judgehost page before it's assigned
- Verify that "-" or similar placeholder is displayed for unstarted judgings
- Verify that judgings with valid start times still display correctly
- Test with judgings in various states (queued, running, completed)
Additional Context
This issue became apparent after migrating from DOMjudge 7.3.3 to version 9.x, where the stricter PHP type declarations exposed the bug. The underlying issue likely existed in earlier versions but was silently handled by PHP's type coercion.