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

Installing ddtrace breaks tests with the jsonschema library #9950

Open
fr-ser opened this issue Jul 26, 2024 · 3 comments
Open

Installing ddtrace breaks tests with the jsonschema library #9950

fr-ser opened this issue Jul 26, 2024 · 3 comments
Labels

Comments

@fr-ser
Copy link

fr-ser commented Jul 26, 2024

Summary of problem

Just installing (not even using) the newest version of ddtrace causes the tests to break, when the jsonschema package is used.

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

2.9.3

Which version of pip are you using?

pip 23.3.2 (python 3.8)

Which libraries and their versions are you using?

`pip freeze` attrs==23.2.0 exceptiongroup==1.2.2 importlib_resources==6.4.0 iniconfig==2.0.0 jsonschema==4.23.0 jsonschema-specifications==2023.12.1 packaging==24.1 pkgutil_resolve_name==1.3.10 pluggy==1.5.0 pytest==8.3.2 referencing==0.35.1 rpds-py==0.19.1 tomli==2.0.1 zipp==3.19.2

How can we reproduce your problem?

Here is a repository with a reproducible example: https://github.com/fr-ser/bug-example-ddtrace-jsonschema

Here is a summary of that repo:

  1. Install the environment: poetry install --no-root
  2. Run the test: poetry run pytest
  3. See an error
  4. uninstall ddtrace: poetry remove ddtrace
  5. run the test: poetry run pytest
  6. it works ¯_(ツ)_/¯

What is the result that you get?

    test_main.py:1: in <module>
        import jsonschema
    <frozen importlib._bootstrap>:991: in _find_and_load
        ???
    <frozen importlib._bootstrap>:975: in _find_and_load_unlocked
        ???
    <frozen importlib._bootstrap>:671: in _load_unlocked
        ???
    .venv/lib/python3.8/site-packages/ddtrace/internal/module.py:220: in _exec_module
        self.loader.exec_module(module)
    .venv/lib/python3.8/site-packages/jsonschema/__init__.py:16: in <module>
        from jsonschema.validators import (
    <frozen importlib._bootstrap>:991: in _find_and_load
        ???
    <frozen importlib._bootstrap>:975: in _find_and_load_unlocked
        ???
    <frozen importlib._bootstrap>:671: in _load_unlocked
        ???
    .venv/lib/python3.8/site-packages/ddtrace/internal/module.py:220: in _exec_module
        self.loader.exec_module(module)
    .venv/lib/python3.8/site-packages/jsonschema/validators.py:603: in <module>
        meta_schema=SPECIFICATIONS.contents(
    .venv/lib/python3.8/site-packages/referencing/_core.py:483: in contents
        return self[uri].contents
    .venv/lib/python3.8/site-packages/referencing/_core.py:333: in __getitem__
        raise exceptions.NoSuchResource(ref=uri) from None
    E   referencing.exceptions.NoSuchResource: 'http://json-schema.org/draft-03/schema#'
    ========================================================================================================== short test summary info ===========================================================================================================
    ERROR test_main.py - referencing.exceptions.NoSuchResource: 'http://json-schema.org/draft-03/schema#'

What is the result that you expected?

No error

@emmettbutler
Copy link
Collaborator

Thanks for reporting this, @fr-ser - it's a weird one! We'll look into it.

@fr-ser
Copy link
Author

fr-ser commented Jul 30, 2024

By now I know that the error is fixed with Python 3.9 if that helps

@timmc-edx
Copy link

timmc-edx commented Aug 2, 2024

Even weirder, when I just run using pytest I don't get the error, but if I run our tests using tox I do get the error. I can't figure out what the environmental difference is! For reference, this is happening in branch timmc/repro-ddtrace-jsonschema of https://github.com/edx/edx-arch-experiments with Python 3.11. In a 3.11 virtualenv, run make requirements and then tox -e py38-django42 to run tests. I'll see if there's a version combo that changes things...

[EDIT] ...never mind, tox was controlling the version of Python! I can confirm that if I bump to 3.11 inside tox, it works fine. It's just with 3.8 that I see the problem.

timmc-edx added a commit to edx/edx-arch-experiments that referenced this issue Aug 2, 2024
- Install ddtrace at the test.in level
- Add tests for new and existing middleware functionality
- Test with Python 3.11, not 3.8. This isn't just because we're upgrading
  to 3.11 across our repos, but also because I ran into a really weird bug
  with ddtrace and/or jsonschema that only occurs with Python 3.8:
  DataDog/dd-trace-py#9950
timmc-edx added a commit to edx/edx-arch-experiments that referenced this issue Aug 5, 2024
- Detect and log anomalous traces in DatadogDiagnosticMiddleware.
- Drop Python 3.8 support and change to Python 3.11 minimum due to testing needs.
- Add tests for existing middleware code

Manual testing:

1. Install in devstack, add middleware to lms/envs/devstack.py, and
   enable Waffle flag.
2. Make some requests and observe lack of new logging.
3. Add `self.dd_tracer.current_root_span().finish()` to start of
   `process_view` (faking an anomalous trace) and reinstall in devstack
4. Make some more requests and observe log output like the following:
   `Anomalous Datadog local root span (duration already set): id = 66abf66b000000001168265a391d04a3; duration = 0.108 sec; worker age = 1.560 sec`

Unit test improvements:

- Install ddtrace at the test.in level
- Add tests for new and existing middleware functionality
- Test with Python 3.11, not 3.8. This isn't just because we're upgrading
  to 3.11 across our repos, but also because I ran into a really weird bug
  with ddtrace and/or jsonschema that only occurs with Python 3.8:
  DataDog/dd-trace-py#9950
@github-actions github-actions bot added the stale label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants