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

Handle incompatible cffi versions when trying to load C extensions in cryptography #234

Open
Tracked by #12682
rtibbles opened this issue Oct 25, 2024 · 0 comments

Comments

@rtibbles
Copy link
Member

Observed behavior

When running on Python 3.13, the cryptography package requires version 1.17.1 of the cffi package. In Kolibri, the cffi package is pinned to 1.15.1 to maintain Python 3.6 and 3.7 support.

As a result, importing cryptography in Morango under these conditions results in an unrecoverable error.

Errors and logs

ImportError: /home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/_cffi_backend.cpython-313-x86_64-linux-gnu.so: undefined symbol: _PyErr_WriteUnraisableMsg
thread '<unnamed>' panicked at 'Python API call failed', /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.15.2/src/err/mod.rs:582:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/bin/kolibri", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/runner/work/kolibri/kolibri/kolibri/utils/cli.py", line 189, in invoke
    initialize(**get_initialize_params())
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/kolibri/kolibri/kolibri/utils/main.py", line 331, in initialize
    _setup_django()
    ~~~~~~~~~~~~~^^
  File "/home/runner/work/kolibri/kolibri/kolibri/utils/main.py", line 150, in _setup_django
    django.setup()
    ~~~~~~~~~~~~^^
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/django/apps/config.py", line [30](https://github.com/learningequality/kolibri/actions/runs/11509302513/job/32039154139?pr=12746#step:6:31)1, in import_models
    self.models_module = import_module(models_module_name)
                         ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.13.0/x64/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 13[31](https://github.com/learningequality/kolibri/actions/runs/11509302513/job/32039154139?pr=12746#step:6:32), in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1022, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/runner/work/kolibri/kolibri/kolibri/core/auth/models.py", line 35, in <module>
    from morango.models import Certificate
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/morango/models/__init__.py", line 1, in <module>
    from morango.models import signals
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/morango/models/signals.py", line 4, in <module>
    from .core import SyncableModel
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/morango/models/core.py", line [32](https://github.com/learningequality/kolibri/actions/runs/11509302513/job/32039154139?pr=12746#step:6:33), in <module>
    from morango.models.certificates import Certificate
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/morango/models/certificates.py", line 15, in <module>
    from .fields.crypto import Key
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/morango/models/fields/__init__.py", line 1, in <module>
    from morango.models.fields.crypto import PrivateKeyField
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/morango/models/fields/crypto.py", line 26, in <module>
    crypto_backend = default_backend()
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/cryptography/hazmat/backends/__init__.py", line 8, in default_backend
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 6, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 13, in <module>
    from cryptography import utils, x[50](https://github.com/learningequality/kolibri/actions/runs/11509302513/job/32039154139?pr=12746#step:6:51)9
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/cryptography/x509/__init__.py", line 6, in <module>
    from cryptography.x509 import certificate_transparency
  File "/home/runner/work/kolibri/kolibri/.tox/py3.13/lib/python3.13/site-packages/cryptography/x509/certificate_transparency.py", line 10, in <module>
    from cryptography.hazmat.bindings._rust import x509 as rust_x509
pyo3_runtime.PanicException: Python API call failed

From this test run: https://github.com/learningequality/kolibri/actions/runs/11509302513/job/32039154139?pr=12746

Expected behavior

We should catch this error, show a warning, and carry on without using the cryptography package

User-facing consequences

Kolibri cannot run on Python 3.13 while maintaining compatibility for Python 3.6 and 3.7 in its statically bundled whl file.

Steps to reproduce

Try to run Kolibri with Python 3.13, using the code from learningequality/kolibri#12746

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

1 participant