Error in using sdk in Symfony with caching
SweetSallyBe opened this issue · 2 comments
When I get a model from the graph, I get the correct model. But I'm using caching in Symfony to save requests.
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($type, $email) {
$item->expiresAfter(self::CACHE_EXPIRES_IN_SECONDS_SHORT);
try {
$requestConfig
= new GroupsRequestBuilderGetRequestConfiguration(queryParameters: GroupsRequestBuilderGetRequestConfiguration::createQueryParameters(filter: 'startsWith(mail,\''
. $email . '\')'));
$groups = $this->graphClient->groups()->get($requestConfig)->wait()->getValue();
if ($groups) {
foreach ($groups as $group) {
if ($group instanceof \Microsoft\Graph\Generated\Models\Group && $group->getMail() == $email) {
return $group;
}
}
}
return null;
} catch (ApiException $exception) {
$this->handleException($exception);
}
});
In my local machine, this gives no trouble, when testing this.
On my remote machine, I get an error
In DefaultMarshaller.php line 50:
Serialization of 'Closure' is not allowed
It seems the serialization does not work well on this model?
Any suggestions?
Tim
I'm experiencing a similar issue. In my case I'm serializing messages to offload the delivery via a command line background task. The message can't be serialised. This is because the backing store adds subscriptions when objects are set on the message, such as ItemBody and FileAttachments. The subscriptions are closures and can't be serialised.
Here's test version of how I used to serialize my messages:
$message = new Message();
$message->setSubject('Test');
$body = new ItemBody();
$body->setContentType(new BodyType(BodyType::HTML));
$body->setContent('<p>Test</p>');
$message->setBody($body); // Causes a subscription to be set on ItemBody
$test = serialize($message); // This would be stored for the background task.
This bombs at the last line because the wrapped SDK Message cannot be serialised as the ItemBody backing store has a subscription attached for the message which is a closure and can't be serialised.
@SweetSallyBe sorry about this experience. Please try the workarounds suggested in #1556