Re: multiple database support: oracle backend

2007-10-18 Thread Ben Ford
Hi There,
I've had similar problems and it comes down to the line in query.py that
looks in backend and sets QuerySet to _QuerySet or backend.QuesrySet if
there is one... I've also written some code to mitigate against this, and
I'd suggest anyone with an interest gets together on this so that we're not
all running round fixing the same problems! Perhaps it's time to update the
multi-db wiki page to get some ideas together on how we can move forward
with the branch, especially given recent changes in backend and forthcoming
ones in QuerySet stuff. I've been mega busy lately and haven't had time to
write anything up, I also don't have internet at home at the moment so even
emailing might be a bit intermittent!
What do you all think?
Ben


On 18/10/2007, Carlos Hanson <[EMAIL PROTECTED]> wrote:
>
>
> On Oct 17, 1:29 pm, Carlos Hanson <[EMAIL PROTECTED]> wrote:
> > On Oct 17, 12:33 am, koenb <[EMAIL PROTECTED]> wrote:
> >
> > > In the latest patches for multi-db the QuerySet that is returned is no
> > > longer fixed, but varies with the model's manager. That should fix
> > > that problem for now.
> >
> > > Koen
> >
> > I've installed the latest patches for multi-db agains revision 6453.
> > It had the same problem.  Then I removed the import connection and
> > replaced it as suggested and got the following:
> >
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> >   File "/usr/local/lib64/python2.4/site-packages/django/db/models/
> > manager.py", line 65, in all
> > return self.get_query_set()
> >   File "/usr/local/lib64/python2.4/site-packages/django/db/models/
> > manager.py", line 56, in get_query_set
> > QS = self.db.connection.ops.query_set_class(_QuerySet)
> >   File "/usr/local/lib64/python2.4/site-packages/django/db/backends/
> > oracle/base.py", line 96, in query_set_class
> > connection = self.model._default_manager.db.connection
> > AttributeError: 'DatabaseOperations' object has no attribute 'model'
> >
> > > On 17 okt, 09:03, Ian <[EMAIL PROTECTED]> wrote:
> >
> > > > I don't know anything about the multi-db branch, but I imagine that
> > > > whatever QuerySet does to get the correct connection should work in
> > > > OracleQuerySet as well.
> >
> > > > Note the mere existence of OracleQuerySet will still be problematic
> in
> > > > multi-db environments that mix Oracle databases with non-Oracle
> > > > databases, since OracleQuerySet replaces QuerySet entirely when
> Oracle
> > > > is used.  However, OracleQuerySet is a hack that will be going away
> > > > after the QuerySet refactor, which solves both problems in the long
> > > > run.
> >
> > > > Ian
> >
> > I will take a look at what QuerySet does to get the connection and see
> > how it differs from OracleQuerySet.
> >
> > Thanks.  If you have anything else, I appreciate it.  If I happen to
> > solve the problem, you'll see it here.
> >
> > Carlos
>
> I put the following line in the wrong place:
>
>   connection = self.model._default_manager.db.connection
>
> It needs to go in two places in the OracleQuerySet:  first, in the
> iterator() method; second, in the _get_sql_clause() method.  The
> original import made connection a global name, and the reference to
> self.model is not valid at that point.  It must be in the
> OracleQuerySet methods.
>
> Thanks for the help.
>
> Carlos
>
>
> >
>


-- 
Regards,
Ben Ford
[EMAIL PROTECTED]
+6281317958862

--~--~-~--~~~---~--~~
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: multiple database support: oracle backend

2007-10-17 Thread Carlos Hanson

On Oct 17, 1:29 pm, Carlos Hanson <[EMAIL PROTECTED]> wrote:
> On Oct 17, 12:33 am, koenb <[EMAIL PROTECTED]> wrote:
>
> > In the latest patches for multi-db the QuerySet that is returned is no
> > longer fixed, but varies with the model's manager. That should fix
> > that problem for now.
>
> > Koen
>
> I've installed the latest patches for multi-db agains revision 6453.
> It had the same problem.  Then I removed the import connection and
> replaced it as suggested and got the following:
>
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/local/lib64/python2.4/site-packages/django/db/models/
> manager.py", line 65, in all
> return self.get_query_set()
>   File "/usr/local/lib64/python2.4/site-packages/django/db/models/
> manager.py", line 56, in get_query_set
> QS = self.db.connection.ops.query_set_class(_QuerySet)
>   File "/usr/local/lib64/python2.4/site-packages/django/db/backends/
> oracle/base.py", line 96, in query_set_class
> connection = self.model._default_manager.db.connection
> AttributeError: 'DatabaseOperations' object has no attribute 'model'
>
> > On 17 okt, 09:03, Ian <[EMAIL PROTECTED]> wrote:
>
> > > I don't know anything about the multi-db branch, but I imagine that
> > > whatever QuerySet does to get the correct connection should work in
> > > OracleQuerySet as well.
>
> > > Note the mere existence of OracleQuerySet will still be problematic in
> > > multi-db environments that mix Oracle databases with non-Oracle
> > > databases, since OracleQuerySet replaces QuerySet entirely when Oracle
> > > is used.  However, OracleQuerySet is a hack that will be going away
> > > after the QuerySet refactor, which solves both problems in the long
> > > run.
>
> > > Ian
>
> I will take a look at what QuerySet does to get the connection and see
> how it differs from OracleQuerySet.
>
> Thanks.  If you have anything else, I appreciate it.  If I happen to
> solve the problem, you'll see it here.
>
> Carlos

I put the following line in the wrong place:

  connection = self.model._default_manager.db.connection

It needs to go in two places in the OracleQuerySet:  first, in the
iterator() method; second, in the _get_sql_clause() method.  The
original import made connection a global name, and the reference to
self.model is not valid at that point.  It must be in the
OracleQuerySet methods.

Thanks for the help.

Carlos


--~--~-~--~~~---~--~~
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: multiple database support: oracle backend

2007-10-17 Thread Carlos Hanson



On Oct 17, 12:33 am, koenb <[EMAIL PROTECTED]> wrote:
> In the latest patches for multi-db the QuerySet that is returned is no
> longer fixed, but varies with the model's manager. That should fix
> that problem for now.
>
> Koen

I've installed the latest patches for multi-db agains revision 6453.
It had the same problem.  Then I removed the import connection and
replaced it as suggested and got the following:

Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/local/lib64/python2.4/site-packages/django/db/models/
manager.py", line 65, in all
return self.get_query_set()
  File "/usr/local/lib64/python2.4/site-packages/django/db/models/
manager.py", line 56, in get_query_set
QS = self.db.connection.ops.query_set_class(_QuerySet)
  File "/usr/local/lib64/python2.4/site-packages/django/db/backends/
oracle/base.py", line 96, in query_set_class
connection = self.model._default_manager.db.connection
AttributeError: 'DatabaseOperations' object has no attribute 'model'

> On 17 okt, 09:03, Ian <[EMAIL PROTECTED]> wrote:
>
> > I don't know anything about the multi-db branch, but I imagine that
> > whatever QuerySet does to get the correct connection should work in
> > OracleQuerySet as well.
>
> > Note the mere existence of OracleQuerySet will still be problematic in
> > multi-db environments that mix Oracle databases with non-Oracle
> > databases, since OracleQuerySet replaces QuerySet entirely when Oracle
> > is used.  However, OracleQuerySet is a hack that will be going away
> > after the QuerySet refactor, which solves both problems in the long
> > run.
>
> > Ian

I will take a look at what QuerySet does to get the connection and see
how it differs from OracleQuerySet.

Thanks.  If you have anything else, I appreciate it.  If I happen to
solve the problem, you'll see it here.

Carlos


--~--~-~--~~~---~--~~
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: multiple database support: oracle backend

2007-10-17 Thread koenb

In the latest patches for multi-db the QuerySet that is returned is no
longer fixed, but varies with the model's manager. That should fix
that problem for now.

Koen

On 17 okt, 09:03, Ian <[EMAIL PROTECTED]> wrote:
> I don't know anything about the multi-db branch, but I imagine that
> whatever QuerySet does to get the correct connection should work in
> OracleQuerySet as well.
>
> Note the mere existence of OracleQuerySet will still be problematic in
> multi-db environments that mix Oracle databases with non-Oracle
> databases, since OracleQuerySet replaces QuerySet entirely when Oracle
> is used.  However, OracleQuerySet is a hack that will be going away
> after the QuerySet refactor, which solves both problems in the long
> run.
>
> Ian


--~--~-~--~~~---~--~~
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: multiple database support: oracle backend

2007-10-17 Thread Ian

On Oct 16, 6:38 pm, Carlos Hanson <[EMAIL PROTECTED]> wrote:
> I am having trouble with Django revision 6110 patched with multi-
> db-6110.patch.
>
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "/usr/local/lib64/python2.4/site-packages/django/db/models/
> query.py", line 108, in __repr__
> return repr(self._get_data())
>   File "/usr/local/lib64/python2.4/site-packages/django/db/models/
> query.py", line 484, in _get_data
> self._result_cache = list(self.iterator())
>   File "/usr/local/lib64/python2.4/site-packages/django/db/backends/
> oracle/base.py", line 119, in iterator
> cursor.execute(full_query, params)
>   File "/usr/local/lib64/python2.4/site-packages/django/db/backends/
> util.py", line 19, in execute
> return self.cursor.execute(sql, params)
> ProgrammingError: relation "ttsd_schools" does not exist
>
> The problem seems to be in django/db/backends/oracle/base.py on line
> 92:
>
>   from django.db import connection
>
> which is later used to get the cursor.  This seems to bypass the use
> of the database settings in OTHER_DATABASES.  I would expect to use
> connections from django.db rather than connection:
>
>   # Create a manager for named connections
>   connections = LazyConnectionManager()
>
>   # Backwards compatibility: establish the default connection and set
> the
>   # default connection properties at module level, using the lazy
> proxy so that
>   # each thread may have a different default connection, if so
> configured
>   connection_info = LocalizingProxy('connection_info', _local,
> lambda: connections[_default])
>   connection = LocalizingProxy('connection', _local,
>lambda:
> connections[_default].connection)
>
> But I don't see how to get the named connection in oracle/base.py.
>
> If that is clear, I would appreciate any suggestions.
>
> Carlos Hanson


I don't know anything about the multi-db branch, but I imagine that
whatever QuerySet does to get the correct connection should work in
OracleQuerySet as well.

Note the mere existence of OracleQuerySet will still be problematic in
multi-db environments that mix Oracle databases with non-Oracle
databases, since OracleQuerySet replaces QuerySet entirely when Oracle
is used.  However, OracleQuerySet is a hack that will be going away
after the QuerySet refactor, which solves both problems in the long
run.

Ian


--~--~-~--~~~---~--~~
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: multiple database support: oracle backend

2007-10-17 Thread koenb

Sorry Carlos,

those patches are far from complete, and I don't use Oracle myself.

For the moment the backends in the patches use the following to get
the connection:

connection = self.model._default_manager.db.connection

Removing the import and putting in that line should do the trick.

There is plenty more wrong (certainly with that 6110 patch, the 6453
one is a little better), but I haven't had the time to work on it
further.

Koen

> The problem seems to be in django/db/backends/oracle/base.py on line
> 92:
>
>   from django.db import connection
>
> which is later used to get the cursor.  This seems to bypass the use
> of the database settings in OTHER_DATABASES.  I would expect to use
> connections from django.db rather than connection:
>
>   # Create a manager for named connections
>   connections = LazyConnectionManager()
>
>   # Backwards compatibility: establish the default connection and set
> the
>   # default connection properties at module level, using the lazy
> proxy so that
>   # each thread may have a different default connection, if so
> configured
>   connection_info = LocalizingProxy('connection_info', _local,
> lambda: connections[_default])
>   connection = LocalizingProxy('connection', _local,
>lambda:
> connections[_default].connection)
>
> But I don't see how to get the named connection in oracle/base.py.
>
> If that is clear, I would appreciate any suggestions.
>
> Carlos Hanson


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---