# HG changeset patch # User Laurent Peuch # Date 1552552700 -3600 # Node ID c81e29cd8cff3edee44a8a58d925c31dc6ed6e6d # Parent 2c47461fec2195c1046405c178deb3bebc3d3288 [DX] adding error messages to {ResultSet,ActionsRegistry}.possible_actions Try to make it more accessible, when we first encountered these errors it it didn't made any sense to us. diff -r 2c47461fec21 -r c81e29cd8cff cubicweb/cwvreg.py --- a/cubicweb/cwvreg.py Wed Mar 13 14:01:10 2019 +0100 +++ b/cubicweb/cwvreg.py Thu Mar 14 09:38:20 2019 +0100 @@ -250,6 +250,15 @@ key=lambda x: x.order) def possible_actions(self, req, rset=None, **kwargs): + if not kwargs: + raise ValueError("ActionsRegistry.possible_actions should always be " + "called with additional keywords arguments (in " + "addition of req and the optional argument rset) " + "to optimised cache computation but you provided " + "none.\n\nFor exemple if you are working on a view, " + "provide the view as a keyword argument to " + "possible_actions like this: view=my_view.") + if rset is None: actions = self.poss_visible_objects(req, rset=rset, **kwargs) else: diff -r 2c47461fec21 -r c81e29cd8cff cubicweb/rset.py --- a/cubicweb/rset.py Wed Mar 13 14:01:10 2019 +0100 +++ b/cubicweb/rset.py Thu Mar 14 09:38:20 2019 +0100 @@ -103,6 +103,11 @@ """Return possible actions on this result set. Should always be called with the same arguments so it may be computed only once. """ + if not kwargs: + raise ValueError("ResultSet.possible_actions is expecting to receive " + "keywords arguments to be able to compute access to " + "the cache only once but you provided none.") + key = tuple(sorted(kwargs.items())) if self._actions_cache is None: actions = self.req.vreg['actions'].poss_visible_objects( @@ -110,9 +115,12 @@ self._actions_cache = (key, actions) return actions else: - assert key == self._actions_cache[0], \ - 'unexpected new arguments for possible actions (%s vs %s)' % ( - key, self._actions_cache[0]) + if key != self._actions_cache[0]: + raise ValueError("ResultSet.possible_actions expects to always " + "receive the same arguments to compute the " + "cache once, but you've call it with the " + "arguments: '%s' that aren't the same as the " + "previously used combinaison '%s'" % (key, self._actions_cache[0])) return self._actions_cache[1] def __len__(self):