Roundup Tracker - Issues

Issue 1404930

classification
grouping/sorting on link to same class throws traceback
Type: Severity: normal
Components: Database Versions:
process
Status: closed fixed
:
: richard : richard, schlatterbeck
Priority: normal :

Created on 2006-01-13 16:19 by schlatterbeck, last changed 2006-01-13 16:19 by schlatterbeck.

Files
File name Uploaded Description Edit Remove
patch-outerjoin schlatterbeck, 2006-01-13 16:19 Fix as described above
Messages
msg2101 Author: [hidden] (schlatterbeck) Date: 2006-01-13 16:19
I have a class (user) with a link to itself
(supervisor). If I now group by supervisor I get a
database exception because the _user table is used
twice in the generated SQL query (backend is postgresql
but this the code is the same for mysql)

Exception:
psycopg.ProgrammingError: ERROR: table name "_user"
specified more than once select
_user.id,_user._username,_user._lastname from _user
LEFT OUTER JOIN _user on _user._supervisor=_user.id
where ((_user._status in ('1'))) and _user.__retired__
<> 1 order by _user._username,_user._lastname

The solution is to alias the right hand side of the
LEFT OUTER JOIN:

-                        loj.append('LEFT OUTER JOIN %s
on %s=%s.id'%(tn,
-                            o, tn))
-                        o = tn + '._%s'%op
+                        loj.append('LEFT OUTER JOIN %s
as rhs_ on %s=rhs_.id'
+                                  %(tn, o))
+                        o = 'rhs_._%s'%op

Patch attached for rdbms_common and back_mysql (they
use much of redundant code...). Note that the patch is
relative to my previous changes in the feature request: 

https://sourceforge.net/tracker/index.php?func=detail&aid=1379534&group_id=31577&atid=402791

but the bug is present in original 0.8.4 code, too.
History
Date User Action Args
2006-01-13 16:19:01schlatterbeckcreate