Re: can't pickle OracleQuery

2008-08-28 Thread paulh

Many thanks for reply. It might just be of interest to know that what
I was actaully pickling (storing in a session) was not the queryset
itself (since it is large) but the Queryset.query attribute which I
imagined to be just the sql (maybe wrapped in something). Once I'd
encountered the error I did look at the oracle backend and saw that
the OracleQuery was not defined at the module level and thus wouldn't
pickle. It would certainly be handy if the .query attribute were
pickleable even if the queryset itself could not be, then one could
recreate the queryset as the docs (in the section on Pickling
QuerySets) suggest.

Paul Hide

On Aug 28, 5:49 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Thu, 2008-08-28 at 06:51 -0700, paulh wrote:
> > django svn version 8659
> > I have some django code that runs perfectly against postgres
> > (psycopg2), but fails with: PicklingError: Can't pickle  > 'django.db.backends.oracle.query.OracleQuery'>: attribute lookup
> > django.db.backends.oracle.query.OracleQuery failed
> > when run against an Oracle XE database.
>
> > Just wondered whether anyone else had encountered this type of
> > problem.
>
> Yes, it's a known restriction because the OracleQuery class is
> dynamically defined (Python can only normally pickle classes defined at
> the top level). I'm working on what I hope might be a solution for 1.0.
>
> The workaround is to manually convert your queryset to a list and
> pickle/cache the list rather than the queryset. For almost all
> use-cases, that should be equivalent. The case where it fails is when
> you want to unpickle and then call extra queryset methods so, for now,
> don't do that if you're using the Oracle backend.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: can't pickle OracleQuery

2008-08-28 Thread Malcolm Tredinnick


On Thu, 2008-08-28 at 06:51 -0700, paulh wrote:
> django svn version 8659
> I have some django code that runs perfectly against postgres
> (psycopg2), but fails with: PicklingError: Can't pickle  'django.db.backends.oracle.query.OracleQuery'>: attribute lookup
> django.db.backends.oracle.query.OracleQuery failed
> when run against an Oracle XE database.
> 
> Just wondered whether anyone else had encountered this type of
> problem.

Yes, it's a known restriction because the OracleQuery class is
dynamically defined (Python can only normally pickle classes defined at
the top level). I'm working on what I hope might be a solution for 1.0.

The workaround is to manually convert your queryset to a list and
pickle/cache the list rather than the queryset. For almost all
use-cases, that should be equivalent. The case where it fails is when
you want to unpickle and then call extra queryset methods so, for now,
don't do that if you're using the Oracle backend.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---