Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: type 'TracedMongoClient' is not subscriptable #10130

Open
ehemmerlin opened this issue Aug 8, 2024 · 2 comments
Open

TypeError: type 'TracedMongoClient' is not subscriptable #10130

ehemmerlin opened this issue Aug 8, 2024 · 2 comments

Comments

@ehemmerlin
Copy link

Summary of problem

Our Python application is using type checkers and the library PyMongo. "As of version 4.1, PyMongo ships with type hints. With type hints, Python type checkers can easily find bugs before they reveal themselves in your code."
Source: https://pymongo.readthedocs.io/en/stable/examples/type_hints.html

Our Python microservice running on Kubernetes is working, but the following error occurs when adding "admission.datadoghq.com/python-lib.version" : "v2.10.1" to it.

  File "/KA/python_processing/services/__init__.py", line 10, in <module>
    from .resource_service import ResourceService
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "/datadog-lib/ddtrace_pkgs/site-packages-ddtrace-py3.12-manylinux2014/ddtrace/internal/module.py", line 250, in _exec_module
    self.loader.exec_module(module)
  File "/KA/python_processing/services/resource_service.py", line 7, in <module>
    class ResourceService:
  File "/KA/python_processing/services/resource_service.py", line 12, in ResourceService
    def __init__(self, mongo_client: pymongo.MongoClient[Dict[str, Any]]):
                                     ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: type 'TracedMongoClient' is not subscriptable

Removing the use of type checkers in our Python microservices solves temporarily the issue, but we need to use type checkers. So we expect dd-trace-py to be compatible with type checkers.

Which version of dd-trace-py are you using?

2.10.1

Which version of pip are you using?

Python 3.12

Which libraries and their versions are you using?

PyMongo version 4.6.3

How can we reproduce your problem?

Use PyMongo version 4.6.3 and type hints in a Python microservice then add Datadog Python library version 2.10.1 to instrument this microservice.

What is the result that you get?

Our Python microservice crashed with this error

  File "/KA/python_processing/services/__init__.py", line 10, in <module>
    from .resource_service import ResourceService
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "/datadog-lib/ddtrace_pkgs/site-packages-ddtrace-py3.12-manylinux2014/ddtrace/internal/module.py", line 250, in _exec_module
    self.loader.exec_module(module)
  File "/KA/python_processing/services/resource_service.py", line 7, in <module>
    class ResourceService:
  File "/KA/python_processing/services/resource_service.py", line 12, in ResourceService
    def __init__(self, mongo_client: pymongo.MongoClient[Dict[str, Any]]):
                                     ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: type 'TracedMongoClient' is not subscriptable

What is the result that you expected?

Our Python microservice should run without any error when Datadog Python library version 2.10.1 is added to instrument this microservice.

@emmettbutler
Copy link
Collaborator

Thank you for the report, @ehemmerlin. We'll get on it.

cc @mabdinur

@github-actions github-actions bot added the stale label Oct 9, 2024
@iherasymenko
Copy link

Duplicate/related to #7681

@github-actions github-actions bot removed the stale label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants