Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -207,10 +207,8 @@ class Query: ...@@ -207,10 +207,8 @@ class Query:
# Verify result # Verify result
if __debug__: if __debug__:
for (idx, row) in enumerate(result): for row in result:
assert _VerifyResultRow(self._fields, row), \ _VerifyResultRow(self._fields, row)
("Inconsistent result for fields %s in row %s: %r" %
(GetAllFields(self._fields), idx, row))
return result return result
...@@ -256,11 +254,17 @@ def _VerifyResultRow(fields, row): ...@@ -256,11 +254,17 @@ def _VerifyResultRow(fields, row):
@param row: Row data @param row: Row data
""" """
return (len(row) == len(fields) and assert len(row) == len(fields)
compat.all((status == QRFS_NORMAL and _VERIFY_FN[fdef.kind](value)) or errs = []
# Value for an abnormal status must be None for ((status, value), (fdef, _, _)) in zip(row, fields):
(status != QRFS_NORMAL and value is None) if status == QRFS_NORMAL:
for ((status, value), (fdef, _, _)) in zip(row, fields))) 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): def _PrepareFieldList(fields):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment