ASKBOT / askbot-devel

Askbot is a Django/Python Q&A forum. **Contributors README**: https://github.com/ASKBOT/askbot-devel#how-to-contribute. Commercial hosting of Askbot and support are available at https://askbot.com
Other
1.57k stars 627 forks source link

Python 3.10 Support / Django Upgrade? #907

Closed EvanCarroll closed 1 year ago

EvanCarroll commented 1 year ago

When I run askbot-setup on master, I get

Can not run master: Error: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.10/collections/init.py)

You can see the screen here,

************************
*                      *
*   Askbot self-test   *
*                      *
************************

Error: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)

Please run: >pip install html5lib==0.9999999

If I set ASKBOT_SELF_TEST = False in settings.py, I get

/srv/askbot_site # python3 manage.py
Traceback (most recent call last):
  File "/srv/askbot_site/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.10/site-packages/Django-2.2.28-py3.10.egg/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.10/site-packages/Django-2.2.28-py3.10.egg/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/usr/local/lib/python3.10/site-packages/Django-2.2.28-py3.10.egg/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.10/site-packages/Django-2.2.28-py3.10.egg/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.10/site-packages/Django-2.2.28-py3.10.egg/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/local/lib/python3.10/site-packages/askbot-0.11.3-py3.10.egg/askbot/models/__init__.py", line 39, in <module>
    from askbot.models.question import Thread
  File "/usr/local/lib/python3.10/site-packages/askbot-0.11.3-py3.10.egg/askbot/models/question.py", line 21, in <module>
    from askbot import mail
  File "/usr/local/lib/python3.10/site-packages/askbot-0.11.3-py3.10.egg/askbot/mail/__init__.py", line 17, in <module>
    from askbot.utils.html import absolutize_urls
  File "/usr/local/lib/python3.10/site-packages/askbot-0.11.3-py3.10.egg/askbot/utils/html.py", line 7, in <module>
    import html5lib
  File "/usr/local/lib/python3.10/site-packages/html5lib-0.9999999-py3.10.egg/html5lib/__init__.py", line 16, in <module>
    from askbot.deps import somepackage
  File "/usr/local/lib/python3.10/site-packages/html5lib-0.9999999-py3.10.egg/html5lib/html5parser.py", line 7, in <module>
  File "/usr/local/lib/python3.10/site-packages/html5lib-0.9999999-py3.10.egg/html5lib/tokenizer.py", line 19, in <module>
  File "/usr/local/lib/python3.10/site-packages/html5lib-0.9999999-py3.10.egg/html5lib/trie/__init__.py", line 3, in <module>

  File "/usr/local/lib/python3.10/site-packages/html5lib-0.9999999-py3.10.egg/html5lib/trie/py.py", line 6, in <module>
  File "/usr/local/lib/python3.10/site-packages/html5lib-0.9999999-py3.10.egg/html5lib/trie/_base.py", line 3, in <module>
ImportError: cannot import name 'Mapping' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)

I believe the source of the problem is Django 2.x does not support Python 3.10. You can see their support matrix here:

https://docs.djangoproject.com/en/4.0/faq/install/

evgenyfadeev commented 1 year ago

I think it means that some dependency is not supporting python 3.10. I've successfully tested Askbot with Python 3.7-3.9.

gb119 commented 1 year ago

Looks like html5lib v 0.999999 is trying to import Mapping directly from collections when it should be using collections.abc now. It's been deprecated for a while and was finally removed in 3.10.

Looking at the code for html5lib 1.1 it seems to have been fixed, so just upgrading html4lib should fix this particular problem. Whether it then works is a whole other question!

evgenyfadeev commented 1 year ago

I've tried upgrading html5lib, turns out its API has changed and as a result askbot.utils.html.sanitize_html will need to be rewritten. I'll try bleach instead.