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.

Object of type 'QuerySet' is not JSON serializable. Queryset not supporting in function call.

See original GitHub issue

Background task does not work if we pass a queryset inside a method and gives back an error.

user_detail = User.objects.get(id=1)

@background(schedule=datetime.now())
def notify_user(user_detail):
      pass

Object of type ‘QuerySet’ is not JSON serializable.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
philippeowagnercommented, Jan 22, 2019

This is how BGT is designed to work. Just pass the the ID and do the query inside notify_user.

user_id = User.objects.get(id=1)

... 

@background(schedule=datetime.now())
def notify_user(user_id):
      user_detail = User.objects.get(id=user_id)
      ...

0reactions
mukulmantoshcommented, Jan 23, 2019

We have serialised JSONs with thousands of IDs in it.

So how it is more efficient that cron job. Is it not that cron is much better for repeating tasks compared to BGT. Can you give a better use case of BGT for repetitive tasks compared to cron.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<Django object > is not JSON serializable - Stack Overflow
simplejson and json don't work with django objects well. Django's built-in serializers can only serialize querysets filled with django objects:
Read more >
Object of type QuerySet is not JSON serializable - Django Forum
Hello, I'm trying to display some info from models through views as a list of dictionaries in JSON format but I get the...
Read more >
TypeError: Object of type QuerySet is not JSON serializable
In Django, we cannot directly convert queryset into JSON because the Object of type QuerySet is not JSON serializable.
Read more >
Django object is not JSON serializable | Edureka Community
I have the following code for serializing the queryset; def render_to_response(self, context, ** ... both django objects and dicts.
Read more >
Django: "TypeError: [] is not JSON serializable" Why?
Querysets are not serializable out-of-the-box. If you try list(self.items) instead of just self.items , that should work as long as the items themselves...
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