Skip to content

Commit ec7b578

Browse files
committed
Avoid errors from selecting "no selection" on multilink (issue2550722).
As discussed in issue 2550722 there are various cases where selecting "no selection" on a multilink can result in inappropriate errors from Roundup: * If selecting "no selection" produces a null edit (a value was set in the multilink in an edit with an error, then removed again, along with all other changes, in the next form submission), so the page is rendered from the form contents including the "-<id>" value for "no selection" for the multilink. * If creating an item with a nonempty value for a multilink has an error, and the resubmission changes that multilink to "no selection" (and this in turn has subcases, according to whether the creation then succeeds or fails on the resubmission, which need fixes in different places in the Roundup code). All of these cases have in common that it is expected and OK to have a "-<id>" value for a submission for a multilink when <id> is not set in that multilink in the database (because the original attempt to set <id> in that multilink had an error), so the hyperdb.py logic to give an error in that case is thus removed. In the subcase of the second case where the resubmission with "no selection" has an error, the templating code tries to produce a menu entry for the "-<id>" multilink value, which also results in an error, hence the templating.py change to ignore such values in the list for a multilink.
1 parent 60ba1b4 commit ec7b578

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Fixed:
4747
configparser module to Python 2. (Joseph Myers)
4848
- Make non-existent items in history not cause a traceback (Ralf
4949
Schlatterbeck)
50+
- issue2550722: avoid errors from selecting "no selection" on
51+
multilink. (Joseph Myers)
5052

5153

5254
2018-07-13 1.6.0

roundup/cgi/templating.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,10 @@ def menu(self, size=None, height=None, showid=0, additional=[],
23952395

23962396
if value is None:
23972397
value = self._value
2398+
# When rendering from form contents, 'value' may contain
2399+
# elements starting '-' from '- no selection -' having been
2400+
# selected on a previous form submission.
2401+
value = [v for v in value if not v.startswith('-')]
23982402

23992403
linkcl = self._db.getclass(self._prop.classname)
24002404

roundup/hyperdb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,11 @@ def from_raw(self, value, db, klass, propname, itemid, **kw):
259259
try:
260260
curvalue.remove(itemid)
261261
except ValueError:
262-
raise HyperdbValueError(_('property %s: %r is not ' \
263-
'currently an element')%(propname, item))
262+
# This can occur if the edit adding the element
263+
# produced an error, so the form has it in the
264+
# "no selection" choice but it's not set in the
265+
# database.
266+
pass
264267
else:
265268
newvalue.append(itemid)
266269
if itemid not in curvalue:

test/test_hyperdbvals.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ def testMultilink3(self):
183183

184184
self.assertEqual(self._test('multilink3', '', None), [])
185185

186-
with self.assertRaises(hyperdb.HyperdbValueError) as cm:
187-
result = self._test('multilink3', '-valid', None)
188-
self.assertEqual(cm.exception.args,
189-
("property multilink3: 'valid' is not currently an element",))
186+
self.assertEqual(self._test('multilink3', '-valid', None), [])
190187

191188
# vim: set filetype=python ts=4 sw=4 et si

0 commit comments

Comments
 (0)