gitpython-developers / GitPython

GitPython is a python library used to interact with Git repositories.
http://gitpython.readthedocs.org
BSD 3-Clause "New" or "Revised" License
4.63k stars 905 forks source link

TypeError: Protocols cannot be instantiated #1332

Open jessielaf opened 3 years ago

jessielaf commented 3 years ago

I am having a issue with getting the date from a git commit. I keep getting this error:

Traceback (most recent call last):
  File "/code/manage.py", line 19, in <module>
    main()
  File "/code/manage.py", line 15, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/code/commits/management/commands/scan_commits.py", line 35, in handle
    self.create_commits_branch(project, branch)
  File "/code/commits/management/commands/scan_commits.py", line 57, in create_commits_branch
    date=datetime.fromtimestamp(git_commit.committed_date),
  File "/usr/local/lib/python3.9/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/usr/local/lib/python3.9/site-packages/git/objects/commit.py", line 199, in _set_cache_
    self._deserialize(BytesIO(stream.read()))
  File "/usr/local/lib/python3.9/site-packages/git/objects/commit.py", line 528, in _deserialize
    self.tree = Tree(self.repo, hex_to_bin(readline().split()[1]), Tree.tree_id << 12, '')
  File "/usr/local/lib/python3.9/site-packages/git/objects/tree.py", line 215, in __init__
    super(Tree, self).__init__(repo, binsha, mode, path)
  File "/usr/local/lib/python3.9/site-packages/git/objects/base.py", line 168, in __init__
    super(IndexObject, self).__init__(repo, binsha)
  File "/usr/local/lib/python3.9/site-packages/git/objects/base.py", line 56, in __init__
    super(Object, self).__init__()
  File "/usr/local/lib/python3.9/typing.py", line 1083, in _no_init
    raise TypeError('Protocols cannot be instantiated')
TypeError: Protocols cannot be instantiated

I get this error with the python 3.9 in docker. Using version 3.1.20 of GitPython.

jakob-keller commented 3 years ago

I am experiencing the same issue since upgrading to GitPython 3.1.20 and Python 3.9.7. Downgrading GitPython to 3.1.18 fixed it for me.

This could be related to https://github.com/gitpython-developers/GitPython/commit/bc37d1561bfcf1b7971cc8d6d4a6f1ba8fa01fa5

msbuhl commented 3 years ago

I got this error with Python 3.9.7 A downgrade to Python 3.9.6 fixed it for me

Using GitPython 3.1.20

Yobmod commented 3 years ago

Hi, Yeah, this is caused by a change in how python enforces protocol initilisation. But it should also be worked-around in main already ( #1318) - it worked for 3.10.0, just have to test 3.9.7. 3.9.7 tests passed, So will be fixed on next release.

1Mark commented 2 years ago

I had the same issue using python3.9.7 and GitPython 3.1.19. After upgrading to 3.1.24 the error went away.

@Yobmod can we close this?