Skip to content

Restore view factory state on caught exception #61

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

Merged

Conversation

thierry2015
Copy link

What

Restore view factory state on caught exception.

Why

When an exception is thrown while rendering a database view, the rendering state isn't restored, leading to caching issues. This problem can be notably observed within a queue worker, where the application lifecycle doesn't terminate after an exception is caught, leading to subsequent rendering inconsistencies.

The main use case leading to this fix was the following: after failing to render a view used in a queued Mailable (view factory $renderCount was > 0 after the exception was handled), the next sent email using a file-based Blade template was successfully built (counter still ended at > 0, same value as the previous render, different cache keys within the view factory), but the third email being rendered and send (also file-based) contained the previous email context and sections, when both last two emails were derived from the same template (the two templates could be different, as long as they shared the same base template using @extend and @section).

How

When an exception is caught in the render phase, the factory state is restored (see the original View implementation.

How to test

Without this fix, using Tinker, render a DB view that is supposed to throw (e.g. omit a portion of the view-model). In the same Tinker session, render the same file-based template twice, using a different view-model. The second render should contain the previous context.

With this fix, we should no longer be able to replicate this behaviour.

@thierry2015 thierry2015 force-pushed the fix/reset-factory-state-on-exception branch 2 times, most recently from 550f11b to 1d62d0e Compare February 5, 2024 04:36
@thierry2015 thierry2015 force-pushed the fix/reset-factory-state-on-exception branch from 1d62d0e to 623ff42 Compare February 5, 2024 04:38
@Flynsarmy Flynsarmy merged commit b60df20 into Flynsarmy:master Feb 5, 2024
@Flynsarmy
Copy link
Owner

Thanks!

@thierry2015
Copy link
Author

@Flynsarmy Could you also tag the merged commit appropriately (I'm guessing 9.0.2), so we don't have to rely on dev-master / commit hash please?

@Flynsarmy
Copy link
Owner

Done

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.

2 participants