Skip to content

Commit

Permalink
Normalize pending events before saving them and denormalize them afte…
Browse files Browse the repository at this point in the history
…r loading

Fixes #2791.
  • Loading branch information
nickygerritsen committed Nov 24, 2024
1 parent 5de560c commit 583145f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions webapp/src/Service/ExternalContestSourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
Expand Down Expand Up @@ -107,7 +109,7 @@ public function __construct(
protected readonly EventLogService $eventLog,
protected readonly SubmissionService $submissionService,
protected readonly ScoreboardService $scoreboardService,
protected readonly SerializerInterface $serializer,
protected readonly SerializerInterface&DenormalizerInterface&NormalizerInterface $serializer,
#[Autowire('%domjudge.version%')]
string $domjudgeVersion
) {
Expand Down Expand Up @@ -1886,7 +1888,8 @@ protected function addPendingEvent(string $type, string|int $id, Event $event, C
objectId: $id,
data: [$data],
);
$dependencies[$type . '-' . $id] = ['type' => $type, 'id' => $id, 'event' => $event];
$normalizedEvent = $this->serializer->normalize($event, Event::class, ['api_version' => $this->getApiVersion()]);
$dependencies[$type . '-' . $id] = ['type' => $type, 'id' => $id, 'event' => $normalizedEvent];
$this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_DEPENDENCY_MISSING, [
'dependencies' => $dependencies,
]);
Expand Down Expand Up @@ -1917,7 +1920,7 @@ protected function loadPendingEvents(): void

$type = $dependency['type'];
$id = $dependency['id'];
$event = $dependency['event'];
$event = $this->serializer->denormalize($dependency['event'], Event::class, 'json', ['api_version' => $this->getApiVersion()]);

if (!isset($this->pendingEvents[$type][$id])) {
$this->pendingEvents[$type][$id] = [];
Expand Down

0 comments on commit 583145f

Please sign in to comment.