Closed jeffseif closed 3 months ago
Many thanks for doing all the diagnostic work on this! I think you are probably correct. Would you like to open a PR with your proposed fix?
Many thanks for doing all the diagnostic work on this! I think you are probably correct. Would you like to open a PR with your proposed fix?
Yeah, I'm happy to put a PR together. I'm not familiar with the testing setup for this repo, so I'll try to stand up a new test which fails, then make the change I suggested, then see if that test succeeds and no others fail.
And I'll shout if I run into any issues!
@maresb The test setup was smoother than I expected, so I have a PR together here: https://github.com/conda/conda-lock/pull/618
Addressed by https://github.com/conda/conda-lock/pull/618 and available in https://github.com/conda/conda-lock/releases/tag/v2.5.6
Thanks a lot @jeffseif! Also available on PyPI, and will be available on conda-forge as soon as the CDN refreshes.
Checklist
What happened?
The issue
I use
conda-lock
with the--check-input-hash
flag so that my system can skip locking when the dependencies haven't changed. My understanding is that this behavior relies on thecontent_hash
stored within the lock file -- when that matches the hash derived from theenvironment.yaml
locking can be skipped. And when I change the dependencies within myenvironment.yaml
, new hashes will be derived, re-locking will occur, and the content hashes will be written to the lock file. This has been working great withv2.0.0
!However, upon upgrading to
v2.5.3
this behavior no longer seems to work. Specifically, new hashes don't seem to be written into the lock file when a lock file already exists. The result is that the hashes stored within the lock file will no longer match the hash of theenvironment.yaml
andconda-lock
will re-lock dependencies no matter what.Steps to reproduce
First I create a simple lock file:
When the
environment.yaml
's hash matches that within the lock file, re-locking is skipped as desired:When we change the
environment.yaml
, the hashes don't match and re-locking occurs as desired:However, the lock file's hash has not been updated:
And as a result, the
environment.yaml
's hash doesn't match that within the lock file andconda-lock
will re-lock (and still not update the hash):A possible location for the bug
Looking at the changes between v2.0.0 and v2.5.3, I noticed that the logic for merging an existing lock file with the new content was rewritten, adding
new_lock_content = lock_content_to_persist.merge(fresh_lock_content)
. Diving intoLockfile.merge
, we find that it returnsLockfile(..., metadata=other.metadata | self.metadata)
; which in turn returnsLockMeta(..., content_hash={**self.content_hash, **other.content_hash})
.I think the issue is that
other.metadata | self.metadata
is equivalent toother.metadata.__or__(self.metadata)
so that when we are inside ofLockMeta.__or__
,self
andother
are flipped and we are overriding the new (=self
) content hashes with the old (=other
) content hashes.I think the fix would be to swap
other
andself
on this line. However, I'm not certain what side effects this might have elsewhere in the code base.Conda Info
Conda Config
No response
Conda list
No response
Additional Context
No response