sebastienros/fluid

Include statement circular dependency

Opened this issue · 8 comments

I have the root template with include statement
My partial template is empty
When I debug it throws a unit test - it looks fine
When I debug it in runtime - get The maximum level of recursion has been reached. Your script must have a cyclic include statement.

Package v. 2.4.0


var options = new TemplateOptions
            {
                CultureInfo = new CultureInfo("en-US"),
                FileProvider = new PhysicalFileProvider(physicalFileProviderPath),
                MaxRecursion = 5,
                MaxSteps = 5
            };

{% include "sub_template_name" %}

When I remove MaxSteps - my application stacking and memory leak comes.

Could, you, please help me?

Does your {% include "sub_template_name" %} also calls into the same sub template? Then this would ultimately break in any case.

Can you provide a minimal repro?

@sebastienros Thx for quick response

Absolutely not circular dependency :)
As I said before sub_template_name is empty
I tested include statement just
Throw unit tests even in debug mode it looks great
But in runtime - bad. Maybe the problem with .net framework?

I can share you a part of code and folder structure or what do you need else from my side?

Ideally a PR with a unit test that would show the problem, or a minimal Program.cs that I can run locally. You can also try the sharplab.io website and share a link to the repro.

I can't reproduce the problem throw unit tests. When I run tests - it looks fine. Just in runtime, I experiencing this problem.

@kinotavr1996 i was getting this issue when i set MaxSteps to 100, and my template apperently needed more 'steps'. It gives a cyclic recursion exception which is not the right message.

My config now is;

            MaxSteps = 10000,
            MaxRecursion = 100

So as a test try and remove MaxSteps = 5 or set it to 1000 and see if it works.

Edit;

You can see this in;

ExceptionHelper.ThrowMaximumRecursionException();

/// <summary>
        /// Increments the number of statements the current template is processing.
        /// </summary>
        public void IncrementSteps()
        {
            var maxSteps = Options.MaxSteps;
            if (maxSteps > 0 && _steps++ > maxSteps)
            {
                ExceptionHelper.ThrowMaximumRecursionException();
            }
        }

Maybe this should throw a better exception message pointing at the max steps option.

EDIT2:

This is a typo and should instead be ThrowMaximumStatementsException @sebastienros

@sommmen Let me try. Even we can schedule a short google meeting for 5 min and I'll show you how it's looks like if you are interested in

@sommmen

var options = new TemplateOptions
            {
                CultureInfo = new CultureInfo("en-US"),
                FileProvider = new PhysicalFileProvider(physicalFileProviderPath),
                MaxSteps = 10000,
                MaxRecursion = 100
            };

try
            {
                var template = GetTemplate(templatePath);

              

                **query = template.Render(new TemplateContext(orderSearchParams, options));**
            }
            catch (Exception e)
            {
                GELogger.Instance.Error(e, "Can't build proper query.");
            }

on line template.Render code stucking