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

fix: re-render answers file path when producing render context #1840

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

sisp
Copy link
Member

@sisp sisp commented Oct 29, 2024

I've fixed a bug related to rendering a template answers file name/path in combination with _message_before_copy.

The reason for this bug is as follows: When _message_before_copy is set, Copier renders this message before starting the questionnaire, and thus at this point the render context does not include any answers of questions, so rendering the templated _answers_file value leads to an incorrect result – but there's likely no practical reason to render the answers file in the pre-copy message. But rendering the pre-copy message requires the render context which contains the rendered answers file and prior to this PR the rendered answers file value was cached, hence the incorrect value was cached when the first render context was produced for rendering the pre-copy message.

This PR solves the problem by simply re-rendering the answers file path every time a render context is produced.

By the way, this bug would have been caught with less confusion if Copier had supported configuring Jinja with StrictUndefined. 🤓

Fixes #1825.

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.72%. Comparing base (05aa175) to head (6cb92f9).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1840   +/-   ##
=======================================
  Coverage   97.72%   97.72%           
=======================================
  Files          49       49           
  Lines        5229     5238    +9     
=======================================
+ Hits         5110     5119    +9     
  Misses        119      119           
Flag Coverage Δ
unittests 97.72% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pawamoy
Copy link
Contributor

pawamoy commented Oct 29, 2024

Caching! Always tempting us, and stabbing us in the back once we succumbed.

@sisp sisp merged commit 50af258 into copier-org:master Oct 29, 2024
22 checks passed
@sisp sisp deleted the fix/rerender-answers-file-path branch October 29, 2024 19:40
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

Successfully merging this pull request may close these issues.

Answers file templating fails when copy message is provided
2 participants