diff options
| author | William Schwartz <wkschwartz@gmail.com> | 2021-01-04 12:04:28 -0600 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-04-01 14:33:30 +0200 |
| commit | 9ee693bd6cf4074f04ec51c6f3cfe87cad392f12 (patch) | |
| tree | 893e5fba17d522305a35e7f2380164cd57563472 /django/utils/version.py | |
| parent | cfe47b7686df0c4c87270a83d6d7f933323ed7e6 (diff) | |
Fixed #32316 -- Deferred accessing __file__.
Deferred accessing the module-global variable __file__ because the
Python import API does not guarantee it always exists—in particular, it
does not exist in certain "frozen" environments. The following changes
advanced this goal.
Thanks to Carlton Gibson, Tom Forbes, Mariusz Felisiak, and Shreyas
Ravi for review and feedback.
Diffstat (limited to 'django/utils/version.py')
| -rw-r--r-- | django/utils/version.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/utils/version.py b/django/utils/version.py index 50be432942..d8437ad07e 100644 --- a/django/utils/version.py +++ b/django/utils/version.py @@ -77,6 +77,10 @@ def get_git_changeset(): This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers. """ + # Repository may not be found if __file__ is undefined, e.g. in a frozen + # module. + if '__file__' not in globals(): + return None repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) git_log = subprocess.run( 'git log --pretty=format:%ct --quiet -1 HEAD', |
