-
-
Notifications
You must be signed in to change notification settings - Fork 902
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
Unpickled Git object has broken version_info #1836
Labels
Comments
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this issue
Feb 22, 2024
The new test doesn't pass yet, as gitpython-developers#1836 is not yet fixed.
EliahKagan
added a commit
to EliahKagan/GitPython
that referenced
this issue
Feb 22, 2024
For gitpython-developers#1836. This uses a property with the same logic as before for version_info caching, except that the _version_info backing attribute holds the value None, rather than being unset, for the uncomputed state. This rectifies the inconistency between the property's behavior and the way the associated states are represented by its __setstate__ and __getstate__ methods for pickling. Because the Git class only used LazyMixin as an implementation detail of the version_info attribute, it is removed as a subclass.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A
Git
instance produced by pickle deserialization always has aversion_info
ofNone
. This prevents version information from being accessed throughversion_info
. It also causes theversion_info
property not to satisfy its type annotation as a tuple ofint
s (independently of #1830). This is the case whether or notversion_info
has been accessed on the original instance before it was pickled:This is due to an inconsistency in how the state of not yet having computed
version_info
is represented in the backing attribute_version_info
:Git
usesLazyMixin
caching for_version_info
, which treats the attribute as uncomputed when absent and computed when present.Git
defines__getstate__
and__setstate__
for pickling and unpickling to represent state pickling does not preserve by setting attributes toNone
.The
_version_info
attribute is set toNone
on aGit
object created by unpickling, so when accessing theversion_info
property delegates to the_version_info
attribute, its value ofNone
is returned and theif attr == "_version_info"
logic in the_set_cache_
method (inherited fromLazyMixin
and overridden) is never run.The intention is that an unpickled
Git
object haveversion_info
in the uncomputed state. This works for the other two excluded attributes, which use the sameNone
convention as in the__getstate__
and__setstate__
implementations, and which do not use anyLazyMixin
functionality for their caching:GitPython/git/cmd.py
Line 315 in afa5754
GitPython/git/cmd.py
Lines 319 to 323 in afa5754
Unlike
_version_info
, which is managed by_set_cache_
, thecat_file_all
andcat_file_header
attributes are initialized toNone
inGit.__init__
:GitPython/git/cmd.py
Lines 786 to 788 in afa5754
This is natural to fix at the same time as #1829, because a fix for that should change the way caching works.
LazyMixin
caching supports attributes that are computed once and never become stale, soversion_info
/_version_info
should implement caching in a different way to fix #1829, and that can fix this too if consistent with__getstate__
/__setstate__
.The text was updated successfully, but these errors were encountered: