Skip to content

Commit 69860b6

Browse files
author
Richard Jones
committed
rdbms backends not filtering correctly on link=None
1 parent cf7f07a commit 69860b6

File tree

5 files changed

+38
-26
lines changed

5 files changed

+38
-26
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Feature:
1818
2004-??-?? 0.7.6
1919
Fixed:
2020
- rdbms backend full text search failure after import (sf bug 980314)
21+
- rdbms backends not filtering correctly on link=None
2122

2223

2324
2004-06-24 0.7.5

cgi-bin/roundup.cgi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup.cgi,v 1.37 2003-11-03 23:37:06 richard Exp $
19+
# $Id: roundup.cgi,v 1.38 2004-06-29 05:51:38 richard Exp $
20+
21+
import sys
22+
sys.path.insert(0, '/home/richard/src/roundup/roundup/')
2023

2124
# python version check
2225
from roundup import version_check
2326
from roundup.i18n import _
24-
import sys
2527

2628
#
2729
## Configuration

roundup/backends/back_mysql.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -605,20 +605,23 @@ def filter(self, search_matches, filterspec, sort=(None,None),
605605
# note: args are embedded in the query string now
606606
elif isinstance(propclass, Link):
607607
if isinstance(v, type([])):
608-
if '-1' in v:
609-
v = v[:]
610-
v.remove('-1')
611-
xtra = ' or _%s._%s is NULL'%(cn, k)
612-
else:
613-
xtra = ''
614-
if v:
608+
d = {}
609+
for entry in v:
610+
if entry == '-1':
611+
entry = None
612+
d[entry] = entry
613+
l = []
614+
if d.has_key(None) or not d:
615+
del d[None]
616+
l.append('_%s._%s is NULL'%(cn, k))
617+
if d:
618+
v = d.keys()
615619
s = ','.join([a for x in v])
616-
where.append('(_%s._%s in (%s)%s)'%(cn, k, s, xtra))
620+
where.append('(_%s._%s in (%s))'%(cn, k, s))
617621
args = args + v
618-
else:
619-
where.append('_%s._%s is NULL'%(cn, k))
622+
where.append(' or '.join(l))
620623
else:
621-
if v == '-1':
624+
if v in ('-1', None):
622625
v = None
623626
where.append('_%s._%s is NULL'%(cn, k))
624627
else:

roundup/backends/rdbms_common.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.113 2004-06-28 23:13:05 richard Exp $
1+
# $Id: rdbms_common.py,v 1.114 2004-06-29 05:51:38 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -2133,20 +2133,23 @@ def filter(self, search_matches, filterspec, sort=(None,None),
21332133
# note: args are embedded in the query string now
21342134
elif isinstance(propclass, Link):
21352135
if isinstance(v, type([])):
2136-
if '-1' in v:
2137-
v = v[:]
2138-
v.remove('-1')
2139-
xtra = ' or _%s._%s is NULL'%(cn, k)
2140-
else:
2141-
xtra = ''
2142-
if v:
2136+
d = {}
2137+
for entry in v:
2138+
if entry == '-1':
2139+
entry = None
2140+
d[entry] = entry
2141+
l = []
2142+
if d.has_key(None) or not d:
2143+
del d[None]
2144+
l.append('_%s._%s is NULL'%(cn, k))
2145+
if d:
2146+
v = d.keys()
21432147
s = ','.join([a for x in v])
2144-
where.append('(_%s._%s in (%s)%s)'%(cn, k, s, xtra))
2148+
where.append('(_%s._%s in (%s))'%(cn, k, s))
21452149
args = args + v
2146-
else:
2147-
where.append('_%s._%s is NULL'%(cn, k))
2150+
where.append(' or '.join(l))
21482151
else:
2149-
if v == '-1':
2152+
if v in ('-1', None):
21502153
v = None
21512154
where.append('_%s._%s is NULL'%(cn, k))
21522155
else:

test/db_test_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.35 2004-06-28 23:13:06 richard Exp $
18+
# $Id: db_test_base.py,v 1.36 2004-06-29 05:51:38 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -876,6 +876,9 @@ def testFilteringLink(self):
876876
ae, filt = self.filteringSetup()
877877
ae(filt(None, {'status': '1'}, ('+','id'), (None,None)), ['2','3'])
878878
ae(filt(None, {'assignedto': '-1'}, ('+','id'), (None,None)), ['3','4'])
879+
ae(filt(None, {'assignedto': None}, ('+','id'), (None,None)), ['3','4'])
880+
ae(filt(None, {'assignedto': ['-1', None]}, ('+','id'), (None,None)),
881+
['3','4'])
879882

880883
def testFilteringRetired(self):
881884
ae, filt = self.filteringSetup()

0 commit comments

Comments
 (0)