Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in using sdk in Symfony with caching #1471

Open
SweetSallyBe opened this issue Feb 22, 2024 · 2 comments
Open

Error in using sdk in Symfony with caching #1471

SweetSallyBe opened this issue Feb 22, 2024 · 2 comments

Comments

@SweetSallyBe
Copy link

SweetSallyBe commented Feb 22, 2024

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

@ianef
Copy link

ianef commented Jul 10, 2024

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.

@Ndiritu
Copy link
Contributor

Ndiritu commented Jul 12, 2024

@SweetSallyBe sorry about this experience. Please try the workarounds suggested in #1556

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

No branches or pull requests

3 participants