Skip to content

Commit ba0da39

Browse files
authored
Merge pull request #618 from jeffseif/jeffseif/update-content-hashes-inplace
fix: Ensure that content hashes are updated for an existing lock file when re-locking
2 parents 4448144 + 55747d2 commit ba0da39

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

conda_lock/lockfile/v2prelim/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def merge(self, other: "Optional[Lockfile]") -> "Lockfile":
6565

6666
# Resort the conda packages topologically
6767
final_package = self._toposort(package)
68-
return Lockfile(package=final_package, metadata=other.metadata | self.metadata)
68+
return Lockfile(package=final_package, metadata=self.metadata | other.metadata)
6969

7070
def toposort_inplace(self) -> None:
7171
self.package = self._toposort(self.package)

tests/test_conda_lock.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,3 +2729,30 @@ def test_pip_full_whl_url(
27292729
typing_extensions_dep.hash.sha256
27302730
== "8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0"
27312731
)
2732+
2733+
2734+
def test_when_merging_lockfiles_content_hashes_are_updated(
2735+
conda_exe: str,
2736+
monkeypatch: "pytest.MonkeyPatch",
2737+
tmp_path: Path,
2738+
):
2739+
work_path = clone_test_dir(name="test-update", tmp_path=tmp_path)
2740+
monkeypatch.chdir(work_path)
2741+
run_lock(
2742+
environment_files=[work_path / "environment-preupdate.yml"],
2743+
conda_exe=str(conda_exe),
2744+
platforms=["linux-64"],
2745+
)
2746+
2747+
def get_content_hashes_for_lock_file(lock_file: Path) -> typing.Dict[str, str]:
2748+
lock_file_dict = yaml.safe_load(lock_file.read_text())
2749+
return lock_file_dict["metadata"]["content_hash"]
2750+
2751+
preupdate_hashes = get_content_hashes_for_lock_file(work_path / "conda-lock.yml")
2752+
run_lock(
2753+
environment_files=[work_path / "environment-postupdate.yml"],
2754+
conda_exe=str(conda_exe),
2755+
platforms=["linux-64"],
2756+
)
2757+
postupdate_hashes = get_content_hashes_for_lock_file(work_path / "conda-lock.yml")
2758+
assert preupdate_hashes != postupdate_hashes

0 commit comments

Comments
 (0)