Skip to content

Commit 572b03f

Browse files
committed
fix(updating): avoid circular reference when rendering JSON-serialized _copier_conf variable
1 parent 6b5939d commit 572b03f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

copier/_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,8 @@ def _apply_update(self) -> None: # noqa: C901
12441244
dst_path=new_copy / subproject_subdir,
12451245
data={
12461246
k: v
1247-
for k, v in self.answers.combined.items()
1248-
if k not in self.answers.hidden
1247+
for k, v in self._answers_to_remember().items()
1248+
if not k.startswith("_")
12491249
},
12501250
defaults=True,
12511251
quiet=True,

tests/test_updatediff.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,3 +2089,28 @@ def test_skip_if_exists_templated(tmp_path_factory: pytest.TempPathFactory) -> N
20892089

20902090
run_update(str(dst), overwrite=True)
20912091
assert (dst / "skip-if-exists.txt").read_text() == "baz"
2092+
2093+
2094+
def test_render_copier_conf_as_json_without_circular_reference(
2095+
tmp_path_factory: pytest.TempPathFactory,
2096+
) -> None:
2097+
"""See https://github.com/copier-org/copier/issues/2448."""
2098+
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
2099+
2100+
with local.cwd(src):
2101+
build_file_tree(
2102+
{
2103+
"{{ _copier_conf.answers_file }}.jinja": "{{ _copier_answers|to_yaml }}",
2104+
"copier_conf.json.jinja": "{{ _copier_conf|to_json }}",
2105+
}
2106+
)
2107+
git_save(tag="v1")
2108+
2109+
run_copy(str(src), dst, overwrite=True, unsafe=True)
2110+
assert (dst / "copier_conf.json").exists()
2111+
2112+
with local.cwd(dst):
2113+
git_save()
2114+
2115+
run_update(str(dst), overwrite=True, unsafe=True)
2116+
assert (dst / "copier_conf.json").exists()

0 commit comments

Comments
 (0)