@@ -126,7 +126,7 @@ func (ns *Namespace) include(ctx context.Context, name string, dataList ...any)
126126 if err != nil {
127127 return includeResult {err : err }
128128 }
129- return ns .doInclude (ctx , v , dataList ... )
129+ return ns .doInclude (ctx , "" , v , dataList ... )
130130}
131131
132132func (ns * Namespace ) lookup (name string ) (* tplimpl.TemplInfo , error ) {
@@ -144,7 +144,7 @@ func (ns *Namespace) lookup(name string) (*tplimpl.TemplInfo, error) {
144144
145145// include is a helper function that lookups and executes the named partial.
146146// Returns the final template name and the rendered output.
147- func (ns * Namespace ) doInclude (ctx context.Context , templ * tplimpl.TemplInfo , dataList ... any ) includeResult {
147+ func (ns * Namespace ) doInclude (ctx context.Context , key string , templ * tplimpl.TemplInfo , dataList ... any ) includeResult {
148148 var data any
149149 if len (dataList ) > 0 {
150150 data = dataList [0 ]
@@ -170,7 +170,7 @@ func (ns *Namespace) doInclude(ctx context.Context, templ *tplimpl.TemplInfo, da
170170 w = b
171171 }
172172
173- if err := ns .deps .GetTemplateStore ().ExecuteWithContext (ctx , templ , w , data ); err != nil {
173+ if err := ns .deps .GetTemplateStore ().ExecuteWithContextAndKey (ctx , key , templ , w , data ); err != nil {
174174 return includeResult {err : err }
175175 }
176176
@@ -198,6 +198,8 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any
198198 Name : name ,
199199 Variants : variants ,
200200 }
201+ keyString := key .Key ()
202+
201203 depsManagerIn := tpl .Context .GetDependencyManagerInCurrentScope (ctx )
202204 ti , err := ns .lookup (name )
203205 if err != nil {
@@ -206,23 +208,23 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any
206208
207209 if parent := tpl .Context .CurrentTemplate .Get (ctx ); parent != nil {
208210 for parent != nil {
209- if parent .CurrentTemplateInfoOps == ti {
211+ if parent .CurrentTemplateInfoOps == ti && parent . Key == keyString {
210212 // This will deadlock if we continue.
211213 return nil , fmt .Errorf ("circular call stack detected in partial %q" , ti .Filename ())
212214 }
213215 parent = parent .Parent
214216 }
215217 }
216218
217- r , found , err := ns .cachedPartials .cache .GetOrCreate (key . Key () , func (string ) (includeResult , error ) {
219+ r , found , err := ns .cachedPartials .cache .GetOrCreate (keyString , func (string ) (includeResult , error ) {
218220 var depsManagerShared identity.Manager
219221 if ns .deps .Conf .Watching () {
220222 // We need to create a shared dependency manager to pass downwards
221223 // and add those same dependencies to any cached invocation of this partial.
222224 depsManagerShared = identity .NewManager ("partials" )
223225 ctx = tpl .Context .DependencyManagerScopedProvider .Set (ctx , depsManagerShared .(identity.DependencyManagerScopedProvider ))
224226 }
225- r := ns .doInclude (ctx , ti , context )
227+ r := ns .doInclude (ctx , keyString , ti , context )
226228 if ns .deps .Conf .Watching () {
227229 r .mangager = depsManagerShared
228230 }
0 commit comments