check we don't get selection ambiguity: if yes, log error in production env, raise in other modes
--- a/vregistry.py Fri Dec 05 18:06:58 2008 +0100
+++ b/vregistry.py Fri Dec 05 18:07:37 2008 +0100
@@ -334,14 +334,24 @@
raise NoSelectableObject if not object apply
"""
- score, winner = 0, None
+ score, winners = 0, []
for vobject in vobjects:
vobjectscore = vobject.__select__(*args, **kwargs)
if vobjectscore > score:
- score, winner = vobjectscore, vobject
- if winner is None:
+ score, winners = vobjectscore, [vobject]
+ elif vobjectscore > 0 and vobjectscore == score:
+ winners.append(vobject)
+ if not winners:
raise NoSelectableObject('args: %s\nkwargs: %s %s'
% (args, kwargs.keys(), [repr(v) for v in vobjects]))
+ if len(winners) > 1:
+ if self.config.mode == 'installed':
+ self.error('select ambiguity, args: %s\nkwargs: %s %s',
+ args, kwargs.keys(), [repr(v) for v in winners])
+ else:
+ raise Exception('select ambiguity, args: %s\nkwargs: %s %s'
+ % (args, kwargs.keys(), [repr(v) for v in winners]))
+ winner = winners[0]
# return the result of the .selected method of the vobject
return winner.selected(*args, **kwargs)