@@ -126,7 +126,7 @@ func (ns *Namespace) include(ctx context.Context, name string, dataList ...any)
126
126
if err != nil {
127
127
return includeResult {err : err }
128
128
}
129
- return ns .doInclude (ctx , v , dataList ... )
129
+ return ns .doInclude (ctx , "" , v , dataList ... )
130
130
}
131
131
132
132
func (ns * Namespace ) lookup (name string ) (* tplimpl.TemplInfo , error ) {
@@ -144,7 +144,7 @@ func (ns *Namespace) lookup(name string) (*tplimpl.TemplInfo, error) {
144
144
145
145
// include is a helper function that lookups and executes the named partial.
146
146
// 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 {
148
148
var data any
149
149
if len (dataList ) > 0 {
150
150
data = dataList [0 ]
@@ -170,7 +170,7 @@ func (ns *Namespace) doInclude(ctx context.Context, templ *tplimpl.TemplInfo, da
170
170
w = b
171
171
}
172
172
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 {
174
174
return includeResult {err : err }
175
175
}
176
176
@@ -198,6 +198,8 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any
198
198
Name : name ,
199
199
Variants : variants ,
200
200
}
201
+ keyString := key .Key ()
202
+
201
203
depsManagerIn := tpl .Context .GetDependencyManagerInCurrentScope (ctx )
202
204
ti , err := ns .lookup (name )
203
205
if err != nil {
@@ -206,23 +208,23 @@ func (ns *Namespace) IncludeCached(ctx context.Context, name string, context any
206
208
207
209
if parent := tpl .Context .CurrentTemplate .Get (ctx ); parent != nil {
208
210
for parent != nil {
209
- if parent .CurrentTemplateInfoOps == ti {
211
+ if parent .CurrentTemplateInfoOps == ti && parent . Key == keyString {
210
212
// This will deadlock if we continue.
211
213
return nil , fmt .Errorf ("circular call stack detected in partial %q" , ti .Filename ())
212
214
}
213
215
parent = parent .Parent
214
216
}
215
217
}
216
218
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 ) {
218
220
var depsManagerShared identity.Manager
219
221
if ns .deps .Conf .Watching () {
220
222
// We need to create a shared dependency manager to pass downwards
221
223
// and add those same dependencies to any cached invocation of this partial.
222
224
depsManagerShared = identity .NewManager ("partials" )
223
225
ctx = tpl .Context .DependencyManagerScopedProvider .Set (ctx , depsManagerShared .(identity.DependencyManagerScopedProvider ))
224
226
}
225
- r := ns .doInclude (ctx , ti , context )
227
+ r := ns .doInclude (ctx , keyString , ti , context )
226
228
if ns .deps .Conf .Watching () {
227
229
r .mangager = depsManagerShared
228
230
}
0 commit comments