Skip to content

Commit 5795b27

Browse files
author
Richard Jones
committed
fixed RDBMS Class.find() to handle None value in multiple find...
...and a merge from maint-0-7
1 parent e95c78b commit 5795b27

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Fixed:
2727
- better roundup-server usage string (sf bug 973352)
2828
- include "context" always, as documented (sf bug 965447)
2929
- fixed REMOTE_USER (external HTTP Basic auth) (sf bug 977309)
30+
- fixed roundup-admin "find" to use better value parsing
31+
- fixed RDBMS Class.find() to handle None value in multiple find
3032

3133

3234
2004-06-10 0.7.4

roundup/admin.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.72 2004-06-13 00:27:45 richard Exp $
19+
# $Id: admin.py,v 1.73 2004-06-23 23:19:07 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -617,32 +617,15 @@ def do_find(self, args):
617617
# handle the propname=value argument
618618
props = self.props_from_args(args[1:])
619619

620-
# if the value isn't a number, look up the linked class to get the
621-
# number
620+
# convert the user-input value to a value used for find()
622621
for propname, value in props.items():
623-
num_re = re.compile('^\d+$')
624-
if value == '-1':
625-
props[propname] = None
626-
elif not num_re.match(value):
627-
# get the property
628-
try:
629-
property = cl.properties[propname]
630-
except KeyError:
631-
raise UsageError, _('%(classname)s has no property '
632-
'"%(propname)s"')%locals()
633-
634-
# make sure it's a link
635-
if (not isinstance(property, hyperdb.Link) and not
636-
isinstance(property, hyperdb.Multilink)):
637-
raise UsageError, _('You may only "find" link properties')
638-
639-
# get the linked-to class and look up the key property
640-
link_class = self.db.getclass(property.classname)
641-
try:
642-
props[propname] = link_class.lookup(value)
643-
except TypeError:
644-
raise UsageError, _('%(classname)s has no key property')%{
645-
'classname': link_class.classname}
622+
if ',' in value:
623+
values = value.split(',')
624+
else:
625+
values = []
626+
d = props[propname] = {}
627+
for value in values:
628+
d[hyperdb.rawToHyperdb(self.db, cl, None, propname, value)] = 1
646629

647630
# now do the find
648631
try:

roundup/backends/rdbms_common.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.110 2004-06-16 03:54:00 richard Exp $
1+
# $Id: rdbms_common.py,v 1.111 2004-06-23 23:19:07 richard Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -1952,8 +1952,14 @@ def find(self, **propspec):
19521952
elif values is None:
19531953
where.append('_%s is NULL'%prop)
19541954
else:
1955-
allvalues += tuple(values.keys())
1956-
where.append('_%s in (%s)'%(prop, ','.join([a]*len(values))))
1955+
values = values.keys()
1956+
s = ''
1957+
if None in values:
1958+
values.remove(None)
1959+
s = '_%s is NULL or '%prop
1960+
allvalues += tuple(values)
1961+
s += '_%s in (%s)'%(prop, ','.join([a]*len(values)))
1962+
where.append(s)
19571963
tables = ['_%s'%self.classname]
19581964
if where:
19591965
o.append('(' + ' and '.join(where) + ')')

test/db_test_base.py

Lines changed: 8 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.32 2004-06-16 03:54:00 richard Exp $
18+
# $Id: db_test_base.py,v 1.33 2004-06-23 23:19:07 richard Exp $
1919

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

@@ -757,6 +757,13 @@ def testFindLinkUnset(self):
757757
got.sort()
758758
self.assertEqual(got, [one, three])
759759

760+
def testFindMultipleLink(self):
761+
one, two, three, four = self._find_test_setup()
762+
self.assertEqual(self.db.issue.find(status={'1':1, '3':1}),
763+
[one, three, four])
764+
self.assertEqual(self.db.issue.find(assignedto={None:1, '1':1}),
765+
[one, three, four])
766+
760767
def testFindMultilink(self):
761768
one, two, three, four = self._find_test_setup()
762769
got = self.db.issue.find(nosy='2')

0 commit comments

Comments
 (0)