Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9010433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:27:28+00:00 2026-06-16T02:27:28+00:00

from myapp.models import MyModel from cPickle import * tmp = MyModel.objects.all()[:1] print(loads(dumps(t, -1)) ==

  • 0
from myapp.models import MyModel
from cPickle import *

tmp = MyModel.objects.all()[:1]
print(loads(dumps(t, -1)) == t)
#Output is "False"

In my case pickled query result differs from unpickled. I already read here:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#pickling-querysets
that such operations are actually allowed. So – what am I doing wrong?

upd #1: Tried cPickle and regular Pickle – got ‘False’ from both

upd #2: Possible resolution – converting QuerySet to Python list with list(). Found it while reading these: https://docs.djangoproject.com/en/dev/ref/models/querysets/#when-querysets-are-evaluated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:27:29+00:00Added an answer on June 16, 2026 at 2:27 am

    The problem is that you are trying to compare two querysets and querysets doesn’t have a __cmp__ method defined.

    So, you can compare a queryset with itself and you will get this:

    >> tmp == tmp
    True
    

    This is because, as there are no __cmp__ method, == evaluates True if both objects have the same identity (the same memory address). You can read it from here

    So, when you do this:

    >> loads(dumps(tmp, -1)) == tmp
    False
    

    you will get a False as a result because objects have different memory addresses. If you convert queries into a “comparable” object, you can get the behaviour you want. Try with this:

    >> set(loads(dumps(tmp, -1))) == set(tmp)
    True
    

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This view function: @login_required def dashboard(request): from myproject.myapp.models import UserProfile k = UserProfile.objects.get( user=request.user.pk
This is my api.py # myapp/api.py from django.contrib.auth.models import User from tastypie.authorization import Authorization
I tested it with the console. $ python manage.py shell >>> from myapp.models import
I am doing something like this in myproject.myapp.urls : from django.conf.urls.defaults import * urlpatterns
I've got a simple User model, defined like so: # models.py from datetime import
This is my models.py: from tastypie.utils.timezone import now from django.contrib.auth.models import User from django.db
I have a custom class-based view # myapp/views.py from django.views.generic import * class MyView(DetailView):
My application uses a 3rd party dll. If I remove myapp.exe.local file from my
I got hundreads of error reports from my app and all of them is
I registered an app to the django admin with: from django.contrib import admin from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.