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

[BUG] EventEngine alert export crashes on any alert from a device that is a member of a device group #2229

Conversation

lunkwill42
Copy link
Member

Describe the bug
Enabling an export script in eventengine.conf (as one would do to export alerts to Argus) causes the eventengine to sometimes fail to process alerts due to a serialization error.

Apparently, Django 2.2 changes the behavior of QuerySet.values_list(), so that it no longer returns a list, but a ValuesListQuerySet object. NAV's serializer definitions for alerts uses a call to values_list to generate a list of Device Groups that a device is a member of. If the result is an empty QuerySet, everything is just peachy. If, however, the alert comes from a device that is a member of any device group, json.dumps will be asked to dump a ValuesListQuerySet instead of a None value, which it can't, and a TypeError is raised.

To Reproduce
Steps to reproduce the behavior:

  1. Set export=/bin/cat in eventengine.conf
  2. nav restart eventengine
  3. Use tools/eventgenerators/boxstate.py to inject a fake boxDown event for a device that is a member of any device group
  4. See error in eventengine.log

Expected behavior

Serialization should be able to produce a list of device group names, as it did in NAV 5.0.

Traceback

Traceback (most recent call last):
  File "/opt/venvs/nav/lib/python3.7/site-packages/nav/eventengine/engine.py", line 189, in load_new_events
    self.handle_event(event)
  File "/usr/lib/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "/opt/venvs/nav/lib/python3.7/site-packages/nav/eventengine/engine.py", line 255, in handle_event
    self._post_generic_alert(event)
  File "/opt/venvs/nav/lib/python3.7/site-packages/nav/eventengine/engine.py", line 230, in _post_generic_alert
    alert.post()
  File "/opt/venvs/nav/lib/python3.7/site-packages/nav/eventengine/alerts.py", line 146, in post
    export.exporter.export(alert)
  File "/opt/venvs/nav/lib/python3.7/site-packages/nav/eventengine/export.py", line 83, in export
    data = json.dumps(serializer.data, cls=DjangoJSONEncoder)
  File "/usr/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/opt/venvs/nav/lib/python3.7/site-packages/django/core/serializers/json.py", line 124, in default
    return super(DjangoJSONEncoder, self).default(o)
  File "/usr/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type QuerySet is not JSON serializable

Environment (please complete the following information):

  • NAV version installed: 5.1.0

Because:
- Django 2.2 apparently no longer returns a list from a call to
  QuerySet.values_list(), but a ValuesListQuerySet.
- The serializer framework was unable to work with this return type,
  causing a serialization error whenever an alert from a netbox which
  was a member of any DeviceGroup was exported.
@lunkwill42 lunkwill42 added the bug label Dec 3, 2020
@lunkwill42 lunkwill42 added this to the 5.1.1 milestone Dec 3, 2020
@lunkwill42 lunkwill42 requested a review from hmpf December 3, 2020 14:29
@lunkwill42 lunkwill42 self-assigned this Dec 3, 2020
@hmpf
Copy link
Contributor

hmpf commented Dec 4, 2020

I really liked step 1 in how to reproduce I must say.

@lunkwill42 lunkwill42 merged commit af470d9 into Uninett:5.1.x Dec 4, 2020
@lunkwill42 lunkwill42 deleted the bugfix/eventengine-export-serialization-error branch December 4, 2020 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants