Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeError in Twig printtimediff Filter When Judging Has No Start Time #3147

Open
@alessiojr

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:

  1. Newly Created Judgings: When a submission is judged but no judgehost has claimed the judging yet
  2. Queued Judgings: Judgings waiting in the queue for an available judgehost
  3. After Migration: When migrating from older DOMjudge versions with incomplete judgings
  4. Internal Errors: When judgings are created but immediately encounter errors before starting
  5. 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

  1. Defensive Programming: Handles edge cases where timing information is incomplete
  2. User-Friendly: Displays meaningful placeholder instead of crashing
  3. Consistent: Matches the pattern used elsewhere in the codebase for displaying null values
  4. Minimal Change: Simple one-line fix that doesn't affect existing functionality
  5. Type Safe: Maintains type safety while being more permissive about input

Testing Recommendations

  1. Create a submission and immediately view the judgehost page before it's assigned
  2. Verify that "-" or similar placeholder is displayed for unstarted judgings
  3. Verify that judgings with valid start times still display correctly
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /