Skip to content

patch(("pynamodb",)) not working with botocore 1.13 #179

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

Closed
laurent-leconte opened this issue Oct 30, 2019 · 3 comments · Fixed by #181
Closed

patch(("pynamodb",)) not working with botocore 1.13 #179

laurent-leconte opened this issue Oct 30, 2019 · 3 comments · Fixed by #181
Labels

Comments

@laurent-leconte
Copy link

requests was removed from botocore 1.13 (see https://www.awsfeed.com/2019/10/01/removing-the-vendored-version-of-requests-from-botocore/)

However the vendored version of requests is still imported in aws_xray_sdk/ext/pynamodb/patch.py, resulting in an ImportError when trying to patch pynamodb.

Steps to reproduce:

from aws_xray_sdk.core import patch

patch(("pynamodb",))

Running this code with botocore >= 1.13 yields the following stack trace:

Traceback (most recent call last):
  File "test_xray.py", line 3, in <module>
    patch(("pynamodb",))
  File "~/.venv/lib/site-packages/aws_xray_sdk/core/patcher.py", line 96, in patch
    _patch_module(m, raise_errors)
  File "~/.venv/lib/site-packages/aws_xray_sdk/core/patcher.py", line 105, in _patch_module
    _patch(module_to_patch)
  File "~/.venv/lib/site-packages/aws_xray_sdk/core/patcher.py", line 120, in _patch
    imported_module = importlib.import_module(path)
  File "~/.venv/lib/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "~/.venv/lib/site-packages/aws_xray_sdk/ext/pynamodb/__init__.py", line 1, in <module>
    from .patch import patch
  File "~/.venv/lib/site-packages/aws_xray_sdk/ext/pynamodb/patch.py", line 1, in <module>
    import botocore.vendored.requests.sessions
ModuleNotFoundError: No module named 'botocore.vendored.requests.sessions'
@chanchiem chanchiem added the bug label Nov 5, 2019
@chanchiem
Copy link
Contributor

Thank you very much for creating this issue.

What version of PynamoDB are you using? We have internal code to selectively remove patching the vendored requests package based on the version of PynamoDB being used. Please refer to this link to see how that is done.

The logic ultimately relies on the transitive dependency version that PynamoDB is using, so if there's an edge case we are missing, we'd love to find a way to fix it.

@laurent-leconte
Copy link
Author

laurent-leconte commented Nov 6, 2019

This is with pynamodb 4.1.0 and aws_xray_sdk 2.4.2.

Edit: just checked your link, the issue is that botocore.vendored.requests.sessions is imported on the first line of the file. So the ModuleNotFound error is triggered before the patching logic can run. Probably (but I haven't tested) a simple solution would be to move the import statement within the else statement on line 23.

@Dunedan
Copy link
Contributor

Dunedan commented Nov 11, 2019

I just opened a PR (#181) which should solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants