After updating to Scriban 3.2.2, templates are no longer working
See original GitHub issueThis issue was raised as a result of a Twitter conversation.
We have a Scriban template, made up of the following files:
index.sbn
{{-
include 'release-info'
if milestone.target.description
include 'milestone'
end
include 'issues' | string.rstrip
if template_kind == "CREATE"
include 'create/footer'
end
~}}
release_info
{{
if issues.count > 0
if commits.count > 0
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}) which resulted in [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) being closed.
{{ else
}}As part of this release we had [{{ issues.count }} {{ issues.count | string.pluralize "issue" "issues" }}]({{ milestone.target.html_url }}?closed=1) closed.
{{ end
else if commits.count > 0
}}As part of this release we had [{{ commits.count }} {{ commits.count | string.pluralize "commit" "commits" }}]({{ commits.html_url }}).
{{ end -}}
milestone.sbn
{{ milestone.target.description }}
issues
{{ for issue_label in issue_labels
include 'issue-details'
end }}
issue-details
__{{ issue_label }}__
{{ for issue in issues.items["issue_label"]
include 'issue-note'
end }}
issue-note
- [__#{{ issue.number }}__]({{ issue.html_url }}) {{ issue.title }}
create/footer
{{ if config.create.include_footer }}
### {{ config.create.footer_heading }}
{{ if config.create.milestone_replace_text
replace_milestone_title config.create.footer_content config.create.milestone_replace_text milestone.target.title
else
config.create.footer_content
end
end }}
When using this, in combination with a model/context similar to the following (NOTE: issues
, issuesDict
, numberOfCommits
, commitsLink
, _targetMilestone
, previousMilestone
haven’t been shown for brevity):
var templateModel = new
{
Issues = new
{
issues.Count,
Items = issuesDict,
},
Commits = new
{
Count = numberOfCommits,
HtmlUrl = commitsLink,
},
Milestone = new
{
Target = _targetMilestone,
Previous = previousMilestone,
},
IssueLabels = issuesDict.Keys.ToList(),
};
And then rendering the template using the following:
The complete code can be seen in this PR
It all works when using Scriban 2.1.4. However, when trying to run the same code in 3.2.2, we get the following error message in one of our unit tests:
System.AggregateException : One or more errors occurred.
----> Scriban.Syntax.ScriptRuntimeException : resource://default/create/issue-details(3,30) : error : Cannot access target `issues.items` with a null indexer: issues.items[issue_label]
Do you have any suggestions about what needs to be changed in our current usage of Scriban to get this to work in 3.2.2?
Please let me know if you need any more details.
Adding @admiringworm for visibility.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
I think I have enough, I will add a test to cover the regression you have discovered.
Great, thanks for reporting this! 😉