Title: Refreshing doesn't invalidate cached version_info · Issue #1829 · gitpython-developers/GitPython · GitHub
Open Graph Title: Refreshing doesn't invalidate cached version_info · Issue #1829 · gitpython-developers/GitPython
X Title: Refreshing doesn't invalidate cached version_info · Issue #1829 · gitpython-developers/GitPython
Description: The version_info property of Git instances is cached per-instance, while the git.refresh function and Git.refresh class method modify global state. When version_info has been read on a Git instance, refreshing affects the behavior of tha...
Open Graph Description: The version_info property of Git instances is cached per-instance, while the git.refresh function and Git.refresh class method modify global state. When version_info has been read on a Git instance...
X Description: The version_info property of Git instances is cached per-instance, while the git.refresh function and Git.refresh class method modify global state. When version_info has been read on a Git instance...
Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1829
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Refreshing doesn't invalidate cached version_info","articleBody":"The `version_info` property of `Git` instances is cached per-instance, while the `git.refresh` function and `Git.refresh` class method modify global state. When `version_info` has been read on a `Git` instance, refreshing affects the behavior of that instance, but does not invalidate the cache, causing the `version_info` property and dynamic `version` method to give inconsistent results even when no changes to environment variables or the filesystem have occurred.\r\n\r\nHere's an example produced on a CentOS 7 system where I have both the system `git` and a newer upstream `git` installed:\r\n\r\n```text\r\nek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython\r\n❯ type -a git\r\ngit is /home/ek/bin/git\r\ngit is /usr/bin/git\r\n\r\nek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython\r\n❯ git --version\r\ngit version 2.43.0\r\n\r\nek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython\r\n❯ /usr/bin/git --version\r\ngit version 1.8.3.1\r\n\r\nek in 🌐 Eald in GitPython on main via 🐍 v3.12.1 via 🅒 GitPython\r\n❯ python\r\nPython 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0] on linux\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n\u003e\u003e\u003e import git\r\n\u003e\u003e\u003e g1 = git.Git()\r\n\u003e\u003e\u003e g2 = git.Git()\r\n\u003e\u003e\u003e g1.version_info\r\n(2, 43, 0)\r\n\u003e\u003e\u003e git.refresh(\"/usr/bin/git\")\r\n\u003e\u003e\u003e g1.version()\r\n'git version 1.8.3.1'\r\n\u003e\u003e\u003e g2.version()\r\n'git version 1.8.3.1'\r\n\u003e\u003e\u003e g1.version_info\r\n(2, 43, 0)\r\n\u003e\u003e\u003e g2.version_info\r\n(1, 8, 3, 1)\r\n```\r\n\r\nBecause I had accessed `g1.version_info` before refreshing, the stale version information is handed back even after the refresh.\r\n\r\nThis is admittedly consistent with how `version_info` is documented:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/afa575454f85b34800460881cc9c3cd7fe78c8e3/git/cmd.py#L839\r\n\r\nBut it seems to me that the documentation, as currently written, does not prevent it from being surprising. I think that either this should be made clear in the `version_info` property docstring, or the behavior should be changed so that refreshing invalidates all `Git` instances' cached `version_info` properties. I am not sure which is better, because I don't know why `version_info` is cached (and cached per instance).\r\n\r\nThis issue can probably be considered minor. In particular, this does not prevent `FetchInfo.refresh` (which `git.refresh` calls after calling `Git.refresh`) from updating `FetchInfo._flag_map` correctly, because `FetchInfo.refresh` accesses `version_info` on a newly created `Git` instance:\r\n\r\nhttps://github.com/gitpython-developers/GitPython/blob/afa575454f85b34800460881cc9c3cd7fe78c8e3/git/remote.py#L346","author":{"url":"https://github.com/EliahKagan","@type":"Person","name":"EliahKagan"},"datePublished":"2024-02-19T01:54:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1829/GitPython/issues/1829"}
| 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:6cdd7b9e-b213-4d6b-0311-70b812e0fa30 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 995A:3CD341:46D322:5F4C6E:69687695 |
| html-safe-nonce | ea0206a4e3ba2d57fc78e9efcaf638108651726fb5d0a884e0ed0417ab0006c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTVBOjNDRDM0MTo0NkQzMjI6NUY0QzZFOjY5Njg3Njk1IiwidmlzaXRvcl9pZCI6IjQ1Mzc4OTQ5NjQ0NzIzNDYyNjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c589657a8e22ae8229e8de63b4dbd36c03fce5150bf7857d7bb07061e9e69af0 |
| hovercard-subject-tag | issue:2141337377 |
| 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/1829/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f7ca323570966f1c9229c8c8c271f678e80205fd42e6b0760d9f2f3e399e964b/gitpython-developers/GitPython/issues/1829 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f7ca323570966f1c9229c8c8c271f678e80205fd42e6b0760d9f2f3e399e964b/gitpython-developers/GitPython/issues/1829 |
| og:image:alt | The version_info property of Git instances is cached per-instance, while the git.refresh function and Git.refresh class method modify global state. When version_info has been read on a Git instance... |
| 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