[Django]-Dreaded "not the same object error" pickling a queryset.query object

7👍

This may not be the case for everyone, but I was using Ipython notebook and having a similar issue pickling my own class.
The problem turned out to be from a reload call

from dir.my_module import my_class    
reload(dir.my_module)

Removing the reload call and then re-running the import and the cell where the instance of that object was created then allowed it to be pickled.

👤J_Tuck

1👍

not so elegant but perhaps it works:
add the directory of the myfile -module to os.sys.path and use only import myfile in each module where you use myfile. (remove any from segment.segmentengine.models.segment import, anywhere in your project)

👤Remi

0👍

According to this doc, pickling a QuerySet should be not a problem. Thus, the problem should come from other place.

Since you mentined:

EDIT2: I had a typo in the error I displayed above — it was models.QuerySet, not models.mymodel.QuerySet that it was complaining about. There is another nuance here, which is that my models file is broken out into multiple modules, so the error is ACTUALLY:

  1. The second error message you provided look like the same as previous one, is that what you mean?
  2. The error message you provided looks weird. Since you are pickling “queryset.query”, the error should related to the django.db.models.sql.Query class instead of the QuerySet class.

Some modules or classes may have the same name. They will override each other then cause this kind of issue. To make thing easier, I will recommend you to use “import ooo.xxx” instead of “from ooo import *”.

0👍

Your could also try

import ooo.xxx as othername
👤Hassek

Leave a comment