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

Pymongo patch does not work in Python 3.5 #166

Open
julidr opened this issue Jul 9, 2019 · 3 comments
Open

Pymongo patch does not work in Python 3.5 #166

julidr opened this issue Jul 9, 2019 · 3 comments
Labels

Comments

@julidr
Copy link

julidr commented Jul 9, 2019

I tried to patch pymongo in mi project that is in Python 3.5 but when i run it the following error appear:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f81714f5620>
Traceback (most recent call last):
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/aws_xray_sdk/ext/django/apps.py", line 47, in ready
    patch(settings.PATCH_MODULES, ignore_module_patterns=settings.IGNORE_MODULE_PATTERNS)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/aws_xray_sdk/core/patcher.py", line 96, in patch
    _patch_module(m, raise_errors)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/aws_xray_sdk/core/patcher.py", line 105, in _patch_module
    _patch(module_to_patch)
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/aws_xray_sdk/core/patcher.py", line 120, in _patch
    imported_module = importlib.import_module(path)
  File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/aws_xray_sdk/ext/pymongo/__init__.py", line 2, in <module>
    from .patch import patch
  File "/home/julianad/Alkanza/virtualenv/alkanza-django3.5/lib/python3.5/site-packages/aws_xray_sdk/ext/pymongo/patch.py", line 23
    host_and_port_str = f'{host}:{port}'
                                       ^
SyntaxError: invalid syntax

I notice that you are using the f prefix but i think is not compatible with Python 3.5. I removed pymongo from the list of modules to patch and it worked.

I don't know if there is a way to build pymongo patch with a syntax that is compatible with all python versions that you support but i would really appreciate it

@chanchiem
Copy link
Contributor

chanchiem commented Jul 18, 2019

Hey!

Thank you very much for reporting this issue. It looks like the solution should be to use str.format() method instead since this is compatible with Python 3.x and Python 2.x. We'll need to do some more extensive testing to confirm. Please stay tuned!

def started(self, event):
    host, port = event.connection_id
    host_and_port_str = '{host}:{port}'.format(host=host, port=port)
    ...

ref

@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in next 7 days. Thank you for your contributions.

@stale stale bot added the stale label Jan 8, 2022
@NathanielRN
Copy link
Contributor

f strings are not available in Python 3.5. We should either drop support for Python 3.5 (which is EOL) or fix this as suggested above.

@stale stale bot removed the stale label Jan 11, 2022
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