cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
190 stars 109 forks source link

TypeError: Unsupported operand type(s) for |: '_GenericAlias' and 'NoneType' #1053

Closed zalling closed 9 months ago

zalling commented 9 months ago

Describe the bug Today, February 1, 2024, our code utilizing TM1py started failing. It seems there was a new release yesterday, 2.0, that when installed as a project dependency returns the following stacktrace in our app code:

$ python main.py

Traceback (most recent call last):
  File "/path-redacted/main.py", line 1, in <module>
    from myLibrary import components
  File "/path-redacted/mylibrary/__init__.py", line 13, in <module>
    from TM1py import User
  File "/path-redacted/venv/lib/python3.9/site-packages/TM1py/__init__.py", line 18, in <module>
    from TM1py.Objects.Annotation import Annotation
  File "/path-redacted/venv/lib/python3.9/site-packages/TM1py/Objects/__init__.py", line 1, in <module>
    from TM1py.Objects.Annotation import Annotation
  File "/path-redacted/venv/lib/python3.9/site-packages/TM1py/Objects/Annotation.py", line 8, in <module>
    from TM1py.Utils import format_url
  File "/path-redacted/venv/lib/python3.9/site-packages/TM1py/Utils/__init__.py", line 2, in <module>
    from TM1py.Utils.Utils import *
  File "/path-redacted/venv/lib/python3.9/site-packages/TM1py/Utils/Utils.py", line 541, in <module>
    attribute_types_by_dimension: Dict[str, Dict[str, str]] | None = None,
TypeError: unsupported operand type(s) for |: '_GenericAlias' and 'NoneType'

To Reproduce Create a new python virtual environment (I used Python3.9) with two files, requirements.txt and main.py.

requirements.txt

TM1py

main.py:

from TM1py import User

myUser = User(name='zallin')
print(myUser)

When trying to execute python main.py, receive the following stacktrace:

Traceback (most recent call last):
  File "/Users/zallin/rcd-tsp/tm1pychecker/main.py", line 1, in <module>
    from TM1py import User
  File "/Users/zallin/rcd-tsp/tm1pychecker/venv/lib/python3.9/site-packages/TM1py/__init__.py", line 18, in <module>
    from TM1py.Objects.Annotation import Annotation
  File "/Users/zallin/rcd-tsp/tm1pychecker/venv/lib/python3.9/site-packages/TM1py/Objects/__init__.py", line 1, in <module>
    from TM1py.Objects.Annotation import Annotation
  File "/Users/zallin/rcd-tsp/tm1pychecker/venv/lib/python3.9/site-packages/TM1py/Objects/Annotation.py", line 8, in <module>
    from TM1py.Utils import format_url
  File "/Users/zallin/rcd-tsp/tm1pychecker/venv/lib/python3.9/site-packages/TM1py/Utils/__init__.py", line 2, in <module>
    from TM1py.Utils.Utils import *
  File "/Users/zallin/rcd-tsp/tm1pychecker/venv/lib/python3.9/site-packages/TM1py/Utils/Utils.py", line 541, in <module>
    attribute_types_by_dimension: Dict[str, Dict[str, str]] | None = None,
TypeError: unsupported operand type(s) for |: '_GenericAlias' and 'NoneType'

Expected behavior No internal library errors to occur.

Version TM1py 2.0 TM1 Server Version: N/A

MariusWirtz commented 9 months ago

Thanks for raising the issue.

Please upgrade TM1py. I just pushed a new version to PyPI https://pypi.org/project/TM1py/2.0.1/

zalling commented 9 months ago

Running a pip install --upgrade worked to upgrade to 2.0.1. Running the test files succeeds with true expected errors, and our actual app now executes without the | error.

Thanks for the quick update!