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

AbstractEntry import exception due to old beautifulsoup4 #538

Open
ybendana opened this issue May 16, 2018 · 2 comments
Open

AbstractEntry import exception due to old beautifulsoup4 #538

ybendana opened this issue May 16, 2018 · 2 comments

Comments

@ybendana
Copy link

Actual behavior

After updating packages, I got this exception with 0.18.1. I then upgraded to 0.19 hoping it would fix the issue but with the same result:

  File "./manage.py", line 13, in <module>
    execute_from_command_line(sys.argv)
  File "/opt/venv/sgmo/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/opt/venv/sgmo/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/opt/venv/sgmo/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/opt/venv/sgmo/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/opt/venv/sgmo/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/opt/venv/sgmo/lib/python2.7/site-packages/zinnia/models/__init__.py", line 4, in <module>
    from zinnia.models.entry import Entry
  File "/opt/venv/sgmo/lib/python2.7/site-packages/zinnia/models/entry.py", line 6, in <module>
    class Entry(load_model_class(ENTRY_BASE_MODEL)):
  File "/opt/venv/sgmo/lib/python2.7/site-packages/zinnia/models_bases/__init__.py", line 21, in load_model_class
    raise ImproperlyConfigured('%s cannot be imported' % model_path)
django.core.exceptions.ImproperlyConfigured: zinnia.models_bases.entry.AbstractEntry cannot be imported

After rolling back several packages without any success, I went into the debugger and figured out that this was the problem as shown in ipython:

AttributeError                            Traceback (most recent call last)
<ipython-input-1-2ab5f7ff4a9e> in <module>()
----> 1 import bs4
/opt/venv/sgmo/lib/python2.7/site-packages/bs4/__init__.py in <module>()
     28 import warnings
     29 
---> 30 from .builder import builder_registry, ParserRejectedMarkup
     31 from .dammit import UnicodeDammit
     32 from .element import (
/opt/venv/sgmo/lib/python2.7/site-packages/bs4/builder/__init__.py in <module>()
    312 register_treebuilders_from(_htmlparser)
    313 try:
--> 314     from . import _html5lib
    315     register_treebuilders_from(_html5lib)
    316 except ImportError:
/opt/venv/sgmo/lib/python2.7/site-packages/bs4/builder/_html5lib.py in <module>()
     68 
     69 
---> 70 class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
     71 
     72     def __init__(self, soup, namespaceHTMLElements):
AttributeError: 'module' object has no attribute '_base'

This is a known issue with beautifulsoup.

The version of beautifulsoup4 that zinnia requires is >=4.3.2. I had a newer version at 4.4.1 but still had an exception if any other package updates the html5lib to 1.0.1. In my case the culprit was bleach that was required by another package.

Expected behavior

The issue was resolved by upgrading beautifulsoup4 to 4.6.0. Zinnia should require a newer version of this package that works with html5lib==1.0.1.

It would also be great if zinnia could give more information about the AbstractEntry import exception. I noticed from old issues that it has come up before after package updates and it's not an informative error. I think the code of zinnia/models_bases/__init__.py could be modified to print out the traceback which is what i had to do in the debugger to figure out the source of the problem:

try:
    _class = getattr(import_module(module_name), class_name)
    return _class
except (ImportError, AttributeError):
    msg = '%s cannot be imported' % model_path
    # Add traceback info to msg here
    raise ImproperlyConfigured(msg)

Steps to reproduce the issue

  1. ./manage.py shell
  2. ipython; import bs4

Specifications

  • Zinnia version: 0.19
  • Django version: 1.11.12
  • Python version: 2.7.5
  • Operating system: Centos 7.4
  • beautifulsoup: 4.4.1
  • html5lib: 1.0.1

Disclaimer

Before submitting an issue make sure you have:

  • [ X] Read the guidelines for contributing.
  • [ X] Checked for duplicate issues.
  • [ X] Not a support request.
@ochernia
Copy link

ochernia commented Apr 9, 2019

What is the solution to this problem?

@patxidraks
Copy link

Hi,
Same Kind of problem despite a beautifulsoup4 update to 4.9.1 version.

Here is the Log
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/patrick/.local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/patrick/.local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/patrick/.local/lib/python3.8/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "/home/patrick/.local/lib/python3.8/site-packages/django/core/management/init.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "/home/patrick/.local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "/home/patrick/.local/lib/python3.8/site-packages/django/init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/patrick/.local/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/patrick/.local/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/patrick/.local/lib/python3.8/site-packages/zinnia/models/init.py", line 4, in
from zinnia.models.entry import Entry
File "/home/patrick/.local/lib/python3.8/site-packages/zinnia/models/entry.py", line 6, in
class Entry(load_model_class(ENTRY_BASE_MODEL)):
File "/home/patrick/.local/lib/python3.8/site-packages/zinnia/models_bases/init.py", line 21, in load_model_class
raise ImproperlyConfigured('%s cannot be imported' % model_path)
django.core.exceptions.ImproperlyConfigured: zinnia.models_bases.entry.AbstractEntry cannot be imported

Thanks for help

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

3 participants