Commit d1c3c3b3 authored by Iustin Pop's avatar Iustin Pop
Browse files

query: change (debug-mode) field validation errors



Currently, the single assert just checks that the entire row is
consistent (true/false), and dumps the row and field definitions as an
accompanying message. This makes it very hard to understand what failed.

This patch changes this validation to show descriptive messages, which
makes it much faster in diagnosing invalid result.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 0ca7e384
......@@ -207,10 +207,8 @@ class Query:
# Verify result
if __debug__:
for (idx, row) in enumerate(result):
assert _VerifyResultRow(self._fields, row), \
("Inconsistent result for fields %s in row %s: %r" %
(GetAllFields(self._fields), idx, row))
for row in result:
_VerifyResultRow(self._fields, row)
return result
......@@ -256,11 +254,17 @@ def _VerifyResultRow(fields, row):
@param row: Row data
"""
return (len(row) == len(fields) and
compat.all((status == QRFS_NORMAL and _VERIFY_FN[fdef.kind](value)) or
# Value for an abnormal status must be None
(status != QRFS_NORMAL and value is None)
for ((status, value), (fdef, _, _)) in zip(row, fields)))
assert len(row) == len(fields)
errs = []
for ((status, value), (fdef, _, _)) in zip(row, fields):
if status == QRFS_NORMAL:
if not _VERIFY_FN[fdef.kind](value):
errs.append("normal field %s fails validation (value is %s)" %
(fdef.name, value))
elif value is not None:
errs.append("abnormal field %s has a non-None value" % fdef.name)
assert not errs, ("Failed validation: %s in row %s" %
(utils.CommaJoin(errors), row))
def _PrepareFieldList(fields):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment