ValvePython / steam

☁️ Python package for interacting with Steam
http://steam.readthedocs.io
MIT License
1.05k stars 127 forks source link

[BUG] SteamClient fails with an AttributeError when importing Protobuf[4.21.0] #385

Closed Caddox closed 2 years ago

Caddox commented 2 years ago

Description SteamClient will fail with the following traceback when attempting to import protobuf:

Traceback ```bash $ cat test_client.py from steam.client import SteamClient client = SteamClient() $ python test_client.py Traceback (most recent call last): File "/home/caddox/Projects/steam_protobuf/test_client.py", line 1, in from steam.client import SteamClient File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/client/__init__.py", line 28, in from steam.core.cm import CMClient File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/core/cm.py", line 20, in from steam.core.msg import Msg, MsgProto File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/core/msg/__init__.py", line 4, in from steam.core.msg.headers import MsgHdr, ExtendedMsgHdr, MsgHdrProtoBuf, GCMsgHdr, GCMsgHdrProto File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/core/msg/headers.py", line 4, in from steam.protobufs import steammessages_base_pb2 File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/protobufs/steammessages_base_pb2.py", line 35, in _descriptor.EnumValueDescriptor( File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 755, in __new__ _message.Message._CheckCalledFromGeneratedFile() AttributeError: module 'google._upb._message' has no attribute 'Message'. Did you mean: 'CMessage'? $ python -m steam.versions_report steam: 1.2.1 Dependencies: vdf: 3.4 protobuf: 4.21.0rc1 requests: 2.27.1 cachetools: 5.0.0 gevent: 21.12.0 gevent-eventemitter: 2.1 pycryptodomex: 3.14.1 enum34: Not Installed win-inet-pton: Not Installed Python runtime: executable: /home/caddox/Projects/steam_protobuf/bin/python version: 3.10.4 (main, Mar 27 2022, 17:48:11) [GCC 11.2.0] platform: linux System info: system: Linux machine: aarch64 release: 5.17.1-1-aarch64-ARCH version: #1 SMP Mon Mar 28 23:54:20 UTC 2022 ```

This occurs when using protobuf version 4.21.0, but not when using protobuf version 3.20. Protobuf was updated with a major version change in April (see Google's release notes: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates ) which could have produced this bug.

Steps to Reproduce the behavior Using the following files in a python venv:

client = SteamClient()

* File: constraints.txt

protobuf<4.0.0

<details><summary>Current Behavior</summary> 

```bash
$ python -m pip install --no-cache-dir 'steam[client]'
# <install output snipped>
$ python -m steam.versions_report
steam: 1.2.1

Dependencies:
                 vdf: 3.4
            protobuf: 4.21.0rc1
            requests: 2.27.1
          cachetools: 5.0.0
              gevent: 21.12.0
 gevent-eventemitter: 2.1
       pycryptodomex: 3.14.1
              enum34: Not Installed
       win-inet-pton: Not Installed

Python runtime:
          executable: /home/caddox/Projects/steam_protobuf/bin/python
             version: 3.10.4 (main, Mar 27 2022, 17:48:11) [GCC 11.2.0]
            platform: linux

System info:
              system: Linux
             machine: aarch64
             release: 5.17.1-1-aarch64-ARCH
             version: #1 SMP Mon Mar 28 23:54:20 UTC 2022
$ python test_client.py
Traceback (most recent call last):
  File "/home/caddox/Projects/steam_protobuf/test_client.py", line 1, in <module>
    from steam.client import SteamClient
  File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/client/__init__.py", line 28, in <module>
    from steam.core.cm import CMClient
  File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/core/cm.py", line 20, in <module>
    from steam.core.msg import Msg, MsgProto
  File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/core/msg/__init__.py", line 4, in <module>
    from steam.core.msg.headers import MsgHdr, ExtendedMsgHdr, MsgHdrProtoBuf, GCMsgHdr, GCMsgHdrProto
  File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/core/msg/headers.py", line 4, in <module>
    from steam.protobufs import steammessages_base_pb2
  File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/steam/protobufs/steammessages_base_pb2.py", line 35, in <module>
    _descriptor.EnumValueDescriptor(
  File "/home/caddox/Projects/steam_protobuf/lib/python3.10/site-packages/google/protobuf/descriptor.py", line 755, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
AttributeError: module 'google._upb._message' has no attribute 'Message'. Did you mean: 'CMessage'?

Constrained Behavior A temporary fix for this consists of rolling back to protobuf 3.20. This is done as follows: ```bash $ python -m pip install --no-cache-dir -c constraints.txt 'steam[client]' # $ python -m steam.versions_report steam: 1.2.1 Dependencies: vdf: 3.4 protobuf: 3.20.1 requests: 2.27.1 cachetools: 5.0.0 gevent: 21.12.0 gevent-eventemitter: 2.1 pycryptodomex: 3.14.1 enum34: Not Installed win-inet-pton: Not Installed Python runtime: executable: /home/caddox/Projects/steam_protobuf/bin/python version: 3.10.4 (main, Mar 27 2022, 17:48:11) [GCC 11.2.0] platform: linux System info: system: Linux machine: aarch64 release: 5.17.1-1-aarch64-ARCH version: #1 SMP Mon Mar 28 23:54:20 UTC 2022 $ python test_client.py # produces no output, as expected ```

Expected behavior I would expect the exception and traceback not to occur on the current version of Protobuf.

Screenshots N/A

Versions Report Version reports were included with all prior code pastes.

Let me know if this is the wrong place for this!

rossengeorgiev commented 2 years ago

Yes, the version spec for the protobuf dependecy is incorrect. Should be ~= instead of >~

https://github.com/ValvePython/steam/blob/2a572c99c64983b4c96b5057f52135b7f4983f61/requirements.txt#L6