From 89ce4acc135357b803dfb64a93ae256a2f1e3d64 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Wed, 1 Dec 2010 20:41:05 +0100 Subject: [PATCH] query: Improve error checking - Show only field definition, not callback when a result row is inconsistent - Show list of duplicate titles if there are any (module load time) Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Adeodato Simo <dato@google.com> --- lib/query.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/query.py b/lib/query.py index 11f1025a2..9d646948a 100644 --- a/lib/query.py +++ b/lib/query.py @@ -154,7 +154,7 @@ class Query: for (idx, row) in enumerate(result): assert _VerifyResultRow(self._fields, row), \ ("Inconsistent result for fields %s in row %s: %r" % - (self._fields, idx, row)) + (GetAllFields(self._fields), idx, row)) return result @@ -205,9 +205,10 @@ def _PrepareFieldList(fields): @return: Field dictionary for L{Query} """ - assert len(set(fdef.title.lower() - for (fdef, _, _) in fields)) == len(fields), \ - "Duplicate title found" + if __debug__: + duplicates = utils.FindDuplicates(fdef.title.lower() + for (fdef, _, _) in fields) + assert not duplicates, "Duplicate title(s) found: %r" % duplicates result = {} @@ -218,7 +219,8 @@ def _PrepareFieldList(fields): assert FIELD_NAME_RE.match(fdef.name) assert TITLE_RE.match(fdef.title) assert callable(fn) - assert fdef.name not in result, "Duplicate field name found" + assert fdef.name not in result, \ + "Duplicate field name '%s' found" % fdef.name result[fdef.name] = field -- GitLab