question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using error reporters - AttributeError: 'generator' object has no attribute 'load'

See original GitHub issue

I’m trying to set up Sentry as an error reporter for django-q. I have installed django-q-sentry v0.1.1, and I’m using django-q v0.8.1. When I try to run my Django project (i.e. runserver), I get the following error:

Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace object at 0x112841ac8>
Traceback (most recent call last):
  File "/Users/jordan/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/172.4343.24/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 589, in __call__
    return self.original_func(*self.args, **self.kwargs)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django/apps/config.py", line 116, in create
    mod = import_module(mod_path)
  File "/Users/jordan/Development/my_project/venv/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 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django_q/apps.py", line 3, in <module>
    from django_q.conf import Conf
  File "/Users/jordan/Development/my_project/venv/lib/python3.5/site-packages/django_q/conf.py", line 220, in <module>
    'djangoq.errorreporters', name).load()
AttributeError: 'generator' object has no attribute 'load'

My django-q configuration is:

Q_CLUSTER = {
    'name': 'DjangoORM',
    'workers': 4,
    'retry': 120,
    'queue_limit': 50,
    'bulk': 10,
    'orm': 'default',
    'save_limit': 1000,
    'catch_up': False,
    'timeout': 180,
    'error_reporter': {
        'sentry': {
            'dsn': 'https://foo@sentry.io/bar',  # My actual Sentry DSN is here.
        },
    },
}

This error is coming from https://github.com/Koed00/django-q/blob/v0.8.1/django_q/conf.py#L212, specifically the following code:

reporters = []
# iterate through the configured error reporters,
# and instantiate an ErrorReporter using the provided config
for name, conf in error_conf.items():
    Reporter = pkg_resources.iter_entry_points(
            'djangoq.errorreporters', name).load()
    e = Reporter(**conf)
    reporters.append(e)

I’m not very familiar with pkg_resources.iter_entry_points but from what I can see online, it seems like it’s being used incorrectly here. Resources like https://docs.pylonsproject.org/projects/pylons-webframework/en/latest/advanced_pylons/entry_points_and_plugins.html and https://www.programcreek.com/python/example/2010/pkg_resources.iter_entry_points do not use the result of pkg_resources.iter_entry_points directly, but rather they iterate over the result, like so:

available_methods = []
for entry_point in pkg_resources.iter_entry_points(group='authkit.method', name=None):
    available_methods.append(entry_point.load())

I did some debugging and when using pkg_resources.iter_entry_points like django-q currently does, the value returned is indeed a generator, and this causes the AttributeError: 'generator' object has no attribute 'load' when django-q tries to call load() on this generator. When I change this block of code so that I am instead iterating over the value returned by pkg_resources.iter_entry_points like the example above, the entry_point is now an EntryPoint class, which seems to be what you’d actually want to call load() on.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
danielwelchcommented, Jan 15, 2018

@jordanmkoncz Alright, looks like this was due to an error in defining the entry_points in django-q’s setup.py file. As you correctly stated, my intention here was to expose the class as the entry point that would be loaded and instantiated with the configuration provided in a user’s Django settings. Because I used dot notation instead of django-q-sentry:Sentry, pkg_resources was looking for a module named Sentry rather than the class (as explained at the bottom of the docs section here).

I’ve loaded up a sample Django project, sentry account, and errors are successfully reporting with django-q, so in combination with your success, I’m hopeful this will fix this issue. Other plugin writers will just have to avoid my mistake and make sure to use the : notation to expose a class.

2reactions
danielwelchcommented, Jan 15, 2018

@jordanmkoncz I think it’s time for me to do what I of course should have done in the first place: just test and debug this with a live sentry instance myself. Thanks for all of your feedback on this stuff, I’ll get to work on it tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'generator' object has no attribute 'endswith ...
The error is indeed raised in this package, but it "is coming from" (in the sense of "caused by") your code passing the...
Read more >
attributeerror: 'generator' object has no attribute 'query'
The AttributeError is raised in Python when you call an attribute of an object whose type is not supported by the method. For...
Read more >
AttributeError: 'Propagator' object has no attribute ...
I am running Windows 10 and have created a number of virtual environments, using python 3.8, 3.9 and 3.10. Java version in the...
Read more >
Beautiful Soup - Quick Guide - Tutorialspoint
error: ImportError “No module named html.parser” error, then you must be running ... AttributeError: 'NavigableString' object has no attribute 'contents'.
Read more >
Error: AttributeError: 'generator' object has no attribute 'items'
Error : AttributeError: 'generator' object has no attribute 'items' ... Hello, I am getting this error when running oncodrivefml. I have oncodrive ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found