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

kombu.exceptions.EncodeError when trying to execute Job #663

Closed
tim-fiola opened this issue Jul 8, 2021 · 2 comments · Fixed by #693
Closed

kombu.exceptions.EncodeError when trying to execute Job #663

tim-fiola opened this issue Jul 8, 2021 · 2 comments · Fixed by #693
Assignees
Labels
type: bug Something isn't working as expected

Comments

@tim-fiola
Copy link
Contributor

Environment

  • Python version: 3.8.10
  • Nautobot version: 1.1.0b1

Steps to Reproduce

  1. Copy Planned Site Job from Nautobot docs to a .py file $NAUTOBOT_ROOT/jobs/
  2. In Web UI, Extensibility-->Jobs
  3. Run the New Branch job

Expected Behavior

Job to execute

Observed Behavior

Got the following message in the UI:

Server Error
There was a problem with your request. Please contact an administrator.

The complete exception is provided below:

<class 'kombu.exceptions.EncodeError'>

Object of type DeviceType is not JSON serializable

Python version: 3.8.10
Nautobot version: 1.1.0b1
@jathanism jathanism added status: accepted type: bug Something isn't working as expected labels Jul 9, 2021
@jathanism jathanism self-assigned this Jul 9, 2021
@jathanism
Copy link
Contributor

jathanism commented Jul 12, 2021

Oof this one is ugly. I am able to reliably reproduce it and attempts to get nested serialization of model objects using JSON and the NautobotKomboJsonDecoder class will alleviate issues with our objects such as DeviceType, but ultimately results the same error but with ModelState:

Object of type ModelState is not JSON serializable

This is django.db.models.base.ModelState which is the internally cached state of the model. I've never seen this leak before.

I can completely obviate this error scenario entirely by hard-coding these settings in nautobot_config.py:

CELERY_ACCEPT_CONTENT = {"pickle"}
CELERY_RESULT_ACCEPT_CONTENT = CELERY_ACCEPT_CONTENT
CELERY_TASK_SERIALIZER = "pickle"
CELERY_RESULT_SERIALIZER = "pickle"

This forces Celery to use Pickle. This isn't necessarily desirable, but I think we have two options:

  1. Go with Pickle for now while we sort it out
  2. Try to get to the bottom of how to do nested JSON serialize/deserialize for messaging in Celery

@lampwins
Copy link
Member

Given the current feature set in 1.1, pickle would work fine. However the switch to json is driven by the scheduler because args and kwargs have to be stored in the DB. So in a pinch, to get 1.1 we could switch it back to pickle and then figure out what the issue is.

lampwins added a commit to lampwins/nautobot that referenced this issue Jul 14, 2021
jathanism pushed a commit that referenced this issue Jul 15, 2021
Added a `serialize_data()` method to `Job` which handles conversion of `MultiObjectVar` and `ObjectVar` to `pk` values. Then within the job execution we use `deserialize_data()` to convert back to actual querysets and model instances, respectively.

Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
jathanism added a commit that referenced this issue Jul 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants