-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
Cannot update project if source copier.yml
contains {{ _copier_conf|to_json }}
#1929
Comments
With Pydantic v1, we used With Pydantic v2, we now use
I'm not sure why this issue is not caught by our test suite though. |
Could this be related to the version of pydantic I have on my environment? For completeness, here they are (not sure which of the 2 is applicable):
|
For completeness, and those that have a similar problem, you can get around the issue with the following (extremely complex) template construct, which removes the faulty entries from config: - ['{{ _copier_python }}', '{{ _copier_conf.src_path }}/tasks.py', '{{ dict(_copier_conf.items() | rejectattr(0, "in", ["data", "answers"]) | list + [("answers", dict(_copier_conf.answers.items() | rejectattr(0, "equalto", "init")))]) | to_json }}'] |
A naïve question: why do you need to add these 2 entries/functions on the configuration object? |
Backward compatibility 🙂 To be honest I think we could have removed them already but we probably forgot. I would say it's time, but this will need a major bump. |
Describe the problem
Running
copier update --trust --defaults --vcs-ref=HEAD new-foo
will lead to:Template
To Reproduce
foo
with a template containing{{ _copier_conf|to_json }}
, like the one above. Initialise the git repo and commit all changes. I also added atasks.py
file that just echoes the input to screen.copier copy --trust --defaults $(PWD)/foo --vcs-ref=HEAD new-foo
to create a copy callednew-foo
. This copy should contain.copier-answers.yml
(with theproject-name
and control variables for the source git repo), and a copy oftasks.py
(since I did not ignore it).new-foo
and commit the files, so that the update will work next.copier update --trust --defaults --vcs-ref=HEAD new-foo
to reproduce the traceback above.After exploring the source code, the reason for this relates to:
a. The
combined
property of objects of typeAnswerMap
onuser_data.py
(line 98 on copier v9.4.1) contains references to two functions coming from theDEFAULT_DATA
global variable on that module (now
andmake_secret
):b. On line 1012 of
main.py
(copier v9.4.1, method_apply_update()
), arun_copy()
is called withdata = self.answers.combined
(which contains the functions above aside from all other stuff already present on_copier_conf
)c. As a consequence, Jinja2
to_json
converter will choke on trying to convert_copier_conf
to JSON (as pydantic'sto_jsonable_python
will not filter those).Logs
No response
Expected behavior
I'd expect that the update runs smoothly.
Screenshots/screencasts/logs
No response
Operating system
macOS
Operating system distribution and version
macOS 15
Copier version
9.4.1
Python version
3.13
Installation method
local build
Additional context
No response
The text was updated successfully, but these errors were encountered: