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

[5.x] Fix error when serializing eloquent query builders #10189

Merged
merged 2 commits into from
May 28, 2024

Conversation

duncanmcclean
Copy link
Member

@duncanmcclean duncanmcclean commented May 24, 2024

This pull request fixes an issue with the {{ nocache }} tag and Statamic's EloquentQueryBuilder, where passing eloquent query builder instances to partials would cause an error to be thrown:

Serialization of 'PDO' is not allowed

This error was happening due to the PDO object, which is nested in Eloquent's query builder not being serializable. This PR fixes that by removing the connection and grammar properties from the query before serializing, then sets them again when unserializing.

Fixes statamic/eloquent-driver#291.

@jasonvarga
Copy link
Member

This removes the builder when serializing, but does the query still work once its unserialized?

@duncanmcclean
Copy link
Member Author

This removes the builder when serializing, but does the query still work once its unserialized?

Ah, you're right. It didn't.

I've refactored the fix so it removes the connection & grammar properties on the query before serialising, then sets them again when unserializing.

@jasonvarga
Copy link
Member

This is kinda just masking the problem. If you had a regular Laravel query builder instance you'd get the same error. But I'm okay with merging anyway.

@jasonvarga jasonvarga merged commit 55ea07d into 5.x May 28, 2024
18 checks passed
@jasonvarga jasonvarga deleted the fix/eloquent-query-builder-serialization branch May 28, 2024 17:59
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

Successfully merging this pull request may close these issues.

Serialization of 'PDO' is not allowed, when using eloquent assets in a no cache region
2 participants