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

Include statement circular dependency #576

Open
kinotavr1996 opened this issue Jun 8, 2023 · 8 comments
Open

Include statement circular dependency #576

kinotavr1996 opened this issue Jun 8, 2023 · 8 comments

Comments

@kinotavr1996
Copy link

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?

@sebastienros
Copy link
Owner

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?

@kinotavr1996
Copy link
Author

@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?

@kinotavr1996
Copy link
Author

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

@sebastienros
Copy link
Owner

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.

@kinotavr1996
Copy link
Author

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

@sommmen
Copy link

sommmen commented Jun 13, 2023

@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

@kinotavr1996
Copy link
Author

@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

@kinotavr1996
Copy link
Author

@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

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