Title: Unpickled Git object has broken version_info · Issue #1836 · gitpython-developers/GitPython · GitHub
Open Graph Title: Unpickled Git object has broken version_info · Issue #1836 · gitpython-developers/GitPython
X Title: Unpickled Git object has broken version_info · Issue #1836 · gitpython-developers/GitPython
Description: A Git instance produced by pickle deserialization always has a version_info of None. This prevents version information from being accessed through version_info. It also causes the version_info property not to satisfy its type annotation ...
Open Graph Description: A Git instance produced by pickle deserialization always has a version_info of None. This prevents version information from being accessed through version_info. It also causes the version_info prop...
X Description: A Git instance produced by pickle deserialization always has a version_info of None. This prevents version information from being accessed through version_info. It also causes the version_info prop...
Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1836
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unpickled Git object has broken version_info","articleBody":"A `Git` instance produced by pickle deserialization always has a `version_info` of `None`. This prevents version information from being accessed through `version_info`. It also causes the `version_info` property not to satisfy its type annotation as a tuple of `int`s (independently of #1830). This is the case whether or not `version_info` has been accessed on the original instance before it was pickled:\r\n\r\n```python\r\n\u003e\u003e\u003e import pickle, git\r\n\u003e\u003e\u003e g = git.Git()\r\n\u003e\u003e\u003e g.version_info\r\n(2, 34, 1)\r\n\u003e\u003e\u003e g2 = pickle.loads(pickle.dumps(g))\r\n\u003e\u003e\u003e g2.version_info\r\n\u003e\u003e\u003e\r\n```\r\n\r\n```python\r\n\u003e\u003e\u003e import pickle, git\r\n\u003e\u003e\u003e g = git.Git()\r\n\u003e\u003e\u003e g2 = pickle.loads(pickle.dumps(g))\r\n\u003e\u003e\u003e g2.version_info\r\n\u003e\u003e\u003e\r\n```\r\n\r\nThis is due to an inconsistency in how the state of not yet having computed `version_info` is represented in the backing attribute `_version_info`:\r\n\r\n- `Git` uses `LazyMixin` caching for `_version_info`, which treats the attribute as uncomputed when absent and computed when present.\r\n- `Git` defines `__getstate__` and `__setstate__` for pickling and unpickling to represent state pickling does not preserve by setting attributes to `None`.\r\n\r\nThe `_version_info` attribute is set to `None` on a `Git` object created by unpickling, so when accessing the `version_info` property delegates to the `_version_info` attribute, its value of `None` is returned and the `if attr == \"_version_info\"` logic in the `_set_cache_` method (inherited from `LazyMixin` and overridden) is never run.\r\n\r\nThe intention is that an unpickled `Git` object have `version_info` in the uncomputed state. This works for the other two excluded attributes, which use the same `None` convention as in the `__getstate__` and `__setstate__` implementations, and which do not use any `LazyMixin` functionality for their caching:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/afa575454f85b34800460881cc9c3cd7fe78c8e3/git/cmd.py#L315\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/afa575454f85b34800460881cc9c3cd7fe78c8e3/git/cmd.py#L319-L323\r\n\r\nUnlike `_version_info`, which is managed by `_set_cache_`, the `cat_file_all` and `cat_file_header` attributes are initialized to `None` in `Git.__init__`:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/afa575454f85b34800460881cc9c3cd7fe78c8e3/git/cmd.py#L786-L788\r\n\r\nThis 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, so `version_info`/`_version_info` should implement caching in a different way to fix #1829, and that can fix this too if consistent with `__getstate__`/`__setstate__`.","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2024-02-22T03:45:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1836/GitPython/issues/1836"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3c285b94-6556-13b5-e3f6-8c56d3667f32 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF76:284BF6:66B978:8B7D16:696893FB |
| html-safe-nonce | 3d715ed3ab77bc1802d85458fa1540cbaf890d9941913b8c464cf02a3a6506c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjc2OjI4NEJGNjo2NkI5Nzg6OEI3RDE2OjY5Njg5M0ZCIiwidmlzaXRvcl9pZCI6IjQ2ODUzMjEzMDA0ODY3Njg2MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2859da170f151231e16df6850de71e555c69246c429ed947286b35075b6c7510 |
| hovercard-subject-tag | issue:2148121203 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/gitpython-developers/GitPython/1836/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ff2b5a830dae22b10d3f6b42f9d1fa89fbe751536377dba2d97bdf55957da8f7/gitpython-developers/GitPython/issues/1836 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ff2b5a830dae22b10d3f6b42f9d1fa89fbe751536377dba2d97bdf55957da8f7/gitpython-developers/GitPython/issues/1836 |
| og:image:alt | A Git instance produced by pickle deserialization always has a version_info of None. This prevents version information from being accessed through version_info. It also causes the version_info prop... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EliahKagan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 50f46dc2d6192249fd8ebf20e76c800f4f2596d4a5f3ab63dd63a754df154f54 |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fef287f17234b4529a4b112a3d47fe8551e32ddd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width