Closed vandres closed 3 years ago
Hi @vandres,
Sorry, I've been unable to reproduce this error; could you please post the stack trace?
Sure:
2020-06-14 13:01:54 [-][-][6362e26b93774b5ea193d60a5505d37f][error][Exception] Exception: Serialization of 'Closure' is not allowed in /var/www/vendor/yiisoft/yii2/caching/Cache.php:249
Stack trace:
#0 /var/www/vendor/yiisoft/yii2/caching/Cache.php(249): serialize(Array)
#1 /var/www/storage/runtime/compiled_templates/8b/8b95740d6ad3826a4bca35635e01c21fd5995c541a0b3bd798101b5ce3df5b9d.php(42): yii\caching\Cache->set('nocache_81e5d44...', Array, 0)
#2 /var/www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_8d00adf64d4d54dbd4fabae05e5ce3bed78e522941dcb0be030ccf4b6b0d7df4->doDisplay(Array, Array)
#3 /var/www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#4 /var/www/storage/runtime/compiled_templates/50/506f3ad12f8b654b451c1c2bdb73718b430f61d9f2616fc91e0a6d9bf8de3362.php(172): Twig\Template->display(Array)
#5 /var/www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_f1fc65432017a337176e5ca081f516da27111fb84d3f10999df7a26eb5b7de95->doDisplay(Array, Array)
#6 /var/www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#7 /var/www/storage/runtime/compiled_templates/6a/6a6b1002fd9dd9491cf969baddb74c9acada18826a1804a899186000be2f91d6.php(66): Twig\Template->display(Array)
#8 /var/www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_d7cb77acacee14df9694cd4c6c8cd13d18099a5497f95885ad938199cc1ad846->doDisplay(Array, Array)
#9 /var/www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#10 /var/www/storage/runtime/compiled_templates/b8/b8bdac89c4c234673d44ed7df33b3b23cabf5506886550676652dd8a4c3a207f.php(89): Twig\Template->display(Array)
#11 /var/www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_c4ac242900012f07ec3b402a40a469df33777bdb7a1287b74c32d2d8d9b35390->doDisplay(Array, Array)
#12 /var/www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#13 /var/www/storage/runtime/compiled_templates/81/811d75d7062157dbef51b90c75ffb6f993f76b7df2a8a49a0ac8c8d239b1a89c.php(99): Twig\Template->display(Array)
#14 /var/www/vendor/twig/twig/src/Template.php(184): __TwigTemplate_9b8ae0466236dc29d0abbdb6e86c8ce6b243433ca13be657cc4d1ae6ca20d737->block_content(Array, Array)
#15 /var/www/storage/runtime/compiled_templates/81/811d75d7062157dbef51b90c75ffb6f993f76b7df2a8a49a0ac8c8d239b1a89c.php(67): Twig\Template->displayBlock('content', Array, Array)
#16 /var/www/vendor/twig/twig/src/Template.php(184): __TwigTemplate_9b8ae0466236dc29d0abbdb6e86c8ce6b243433ca13be657cc4d1ae6ca20d737->block_body(Array, Array)
#17 /var/www/storage/runtime/compiled_templates/d2/d2e5746a8f64d1c7eb6f6ee370d33d15a487c2532096fca2e9a03e09b813df52.php(99): Twig\Template->displayBlock('body', Array, Array)
#18 /var/www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_6563009811219729a9da14d853c752123cc8c9ae7497a1511ef74ed08d14baa8->doDisplay(Array, Array)
#19 /var/www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#20 /var/www/storage/runtime/compiled_templates/81/811d75d7062157dbef51b90c75ffb6f993f76b7df2a8a49a0ac8c8d239b1a89c.php(52): Twig\Template->display(Array, Array)
#21 /var/www/vendor/twig/twig/src/Template.php(407): __TwigTemplate_9b8ae0466236dc29d0abbdb6e86c8ce6b243433ca13be657cc4d1ae6ca20d737->doDisplay(Array, Array)
#22 /var/www/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#23 /var/www/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#24 /var/www/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#25 /var/www/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#26 /var/www/vendor/craftcms/cms/src/web/View.php(375): Twig\Environment->render('voan/page/_entr...', Array)
#27 /var/www/vendor/craftcms/cms/src/web/View.php(436): craft\web\View->renderTemplate('voan/page/_entr...', '[<span class="s...')
#28 /var/www/vendor/craftcms/cms/src/web/Controller.php(235): craft\web\View->renderPageTemplate('voan/page/_entr...', '[<span class="s...', '<span class="st...')
#29 /var/www/vendor/craftcms/cms/src/controllers/TemplatesController.php(98): craft\web\Controller->renderTemplate('voan/page/_entr...', Array)
#30 [internal function]: craft\controllers\TemplatesController->actionRender('voan/page/_entr...', Array)
#31 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#32 /var/www/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#33 /var/www/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('render', Array)
#34 /var/www/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#35 /var/www/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('templates/rende...', Array)
#36 /var/www/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#37 /var/www/vendor/craftcms/cms/src/web/Application.php(276): yii\web\Application->handleRequest(Object(craft\web\Request))
#38 /var/www/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#39 /var/www/web/index.php(21): yii\base\Application->run()
#40 {main}
Compiled template:
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* voan/_includes/_fields/form */
class __TwigTemplate_8d00adf64d4d54dbd4fabae05e5ce3bed78e522941dcb0be030ccf4b6b0d7df4 extends \Twig\Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->parent = false;
$this->blocks = [
];
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
craft\helpers\Template::beginProfile("template", "voan/_includes/_fields/form");
// line 1
if (craft\helpers\Template::attribute($this->env, $this->source, (isset($context["entry"]) || array_key_exists("entry", $context) ? $context["entry"] : (function () { throw new RuntimeError('Variable "entry" does not exist.', 1, $this->source); })()), "form", [])) {
// line 2
echo " ";
$subContext = ["entry" => (isset($context["entry"]) || array_key_exists("entry", $context) ? $context["entry"] : (function () { throw new RuntimeError('Variable "entry" does not exist.', 2, $this->source); })())];
if (ttempleton\nocache\Plugin::$plugin->methods->isCacheEnabled()) { $contextId = craft\helpers\StringHelper::randomString(8); Craft::$app->getCache()->set('nocache_81e5d44e6f67278814430d7474892220e76fa953050d2da9a41a444080746be3_' . $contextId, $subContext, 0); echo '<no-cache>81e5d44e6f67278814430d7474892220e76fa953050d2da9a41a444080746be3-' . $contextId . '</no-cache>'; } else { echo ttempleton\nocache\Plugin::$plugin->methods->render('81e5d44e6f67278814430d7474892220e76fa953050d2da9a41a444080746be3', $subContext); } }
// line 0
craft\helpers\Template::endProfile("template", "voan/_includes/_fields/form");
}
// line 4
public function macro_errorList($__errors__ = null, ...$__varargs__)
{
$macros = $this->macros;
$context = $this->env->mergeGlobals([
"errors" => $__errors__,
"varargs" => $__varargs__,
]);
$blocks = [];
ob_start();
try {
// line 0
craft\helpers\Template::beginProfile("macro", "errorList");
// line 5
echo " ";
if ((isset($context["errors"]) || array_key_exists("errors", $context) ? $context["errors"] : (function () { throw new RuntimeError('Variable "errors" does not exist.', 5, $this->source); })())) {
// line 6
echo " <small class=\"form-text text-danger\">
";
// line 7
$context['_parent'] = $context;
$context['_seq'] = twig_ensure_traversable((isset($context["errors"]) || array_key_exists("errors", $context) ? $context["errors"] : (function () { throw new RuntimeError('Variable "errors" does not exist.', 7, $this->source); })()));
foreach ($context['_seq'] as $context["_key"] => $context["error"]) {
// line 8
echo " ";
echo twig_escape_filter($this->env, $context["error"], "html", null, true);
echo "
";
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_iterated'], $context['_key'], $context['error'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
// line 10
echo " </small>
";
}
// line 12
echo " ";
// line 0
craft\helpers\Template::endProfile("macro", "errorList");
return ('' === $tmp = ob_get_contents()) ? '' : new Markup($tmp, $this->env->getCharset());
} finally {
ob_end_clean();
}
}
public function getTemplateName()
{
return "voan/_includes/_fields/form";
}
public function isTraitable()
{
return false;
}
public function getDebugInfo()
{
return array ( 88 => 0, 86 => 12, 82 => 10, 73 => 8, 69 => 7, 66 => 6, 63 => 5, 61 => 0, 48 => 4, 44 => 0, 40 => 2, 38 => 1,);
}
public function getSourceContext()
{
return new Source("{% if entry.form %}
{% nocache with {entry: entry} %}
<div class=\"field-form\">
{% macro errorList(errors) %}
{% if errors %}
<small class=\"form-text text-danger\">
{% for error in errors %}
{{ error }}
{% endfor %}
</small>
{% endif %}
{% endmacro %}
{% from _self import errorList %}
{% set form = entry.form.setConfig({
redirect: entry.page is defined ? entry.page.one().url,
submitButton: {
\"type\": \"button\",
\"label\": \"form.submit\" | t,
\"attributes\": {
\"class\": \"btn btn-primary\",
},
}
}) %}
{{ form.open() }}
{{ wheelformErrors['form'] is defined ? errorList(wheelformErrors['form']) }}
{{ wheelformErrors['recaptcha'] is defined ? errorList(wheelformErrors['recaptcha']) }}
{{ wheelformErrors['honeypot'] is defined ? errorList(wheelformErrors['honeypot']) }}
{% for field in form.fields %}
<div class=\"form-group\">
{% switch field.type %}
{% case \"textarea\" %}
<label for=\"{{ field.name }}\">{{ field.label }}</label>
<textarea class=\"form-control\" rows=\"10\" cols=\"40\" name=\"{{ field.name }}\" id=\"{{ field.name }}\">{{ values[field.name] ?? '' }}</textarea>
{% case \"select\" %}
<label for=\"{{ field.name }}\">{{ field.label }}</label>
<select class=\"form-control\" name=\"{{ field.name }}\" id=\"{{ field.name }}\">
<option value=\"\">{{ 'form.select.placeholder' | t }}</option>
{% for item in field.items %}
<option value=\"{{ item }}\" {{ values[field.name] is defined and item == values[field.name] ? 'selected=\"selected\"' : '' }}>{{ item }}</option>
{% endfor %}
</select>
{% case \"input\" %}
<label for=\"{{ field.name }}\">{{ field.label }}</label>
<input class=\"form-control\" type=\"{{ field.type }}\" value=\"{{ values[field.name] ?? '' }}\" name=\"{{ field.name }}\" id=\"{{ field.name }}\"/>
{% endswitch %}
{{ wheelformErrors[field.name] is defined ? errorList(wheelformErrors[field.name]) }}
</div>
{% endfor %}
{{ form.close() }}
</div>
{% endnocache %}
{% endif %}
", "voan/_includes/_fields/form", "/var/www/templates/voan/_includes/_fields/form.twig");
}
}
I think, it may be related that the FormService of the WheelForm-Plugin is combined into that field.
Thanks @vandres. I'll do some testing with a No-Cache/Neo/WheelForm setup and see if I can trigger the error.
Thank you very much. If I can support you anyhow, tell me
Hi @ttempleton Any news on this? :)
You were correct in your previous comment regarding the FormService
being related, as it has a number of closures attached to it; in particular, their JsonFieldBehavior::events()
were attached in my testing. Once you check the existence of entry.form
before using the nocache
tag, the FormService
is on your entry
object, so No-Cache's storage of the entry
in Craft's cache is then doomed to failure.
I don't think this indicates an incompatibility between No-Cache and Wheel Form; just a need to be careful in how they're used together. Moving the if
block within the nocache
block should work (as long as entry.form
hasn't been previously accessed in any way, of course).
Regarding resolving the exception if an element is stored in the nocache
block's context, where the element's Wheel Form field has already been accessed -- unfortunately there's nothing I can really do about that on No-Cache's end, it just tries to cache whatever it's given as the nocache
block's context, and Craft/Yii needs to serialise it, so it would rely on some level of rearchitecture on Wheel Form's part to not directly attach a FormService
as the field value.
Description
I am having a setup, where I cache a whole entry page. Within certain pages, I have a form field, which I want to exclude from cache.
My code looks basically like this:
_entry.twig
form.twig
While having this setup, I get an Exception
Serialization of 'Closure' is not allowed
:in /var/www/vendor/yiisoft/yii2/caching/Cache.php at line 249 – serialize([['entry' => benf\neo\elements\Block], null])
Additional information