Unhelpful error message in multiple_insert() when not all rows have the same keys #183

Closed
benhoyt opened this Issue Oct 1, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@benhoyt
Contributor

benhoyt commented Oct 1, 2012

When you're using db.multiple_insert() and have a bug which means not all rows have the same keys, web.py's db layer gives a rather unhelpful error message:

Traceback (most recent call last):
  ...
  File "web\db.py", line 782, in multiple_insert
    raise ValueError, 'Bad data'
ValueError: Bad data

"Bad data" is not as helpful as it could be. :-)

The code in question is here:

    # make sure all rows have same keys.
    for v in values:
        if v.keys() != keys:
            raise ValueError, 'Bad data'

What about moving the helpful error message from the comment into the exception argument, like so:

    for v in values:
        if v.keys() != keys:
            raise ValueError, 'Not all rows have the same keys'

Could even do this for bonus points:

    for v in values:
        if v.keys() != keys:
            raise ValueError, 'Not all rows have the same keys: %s != %s' % (v.keys(), keys)
@aaronsw

This comment has been minimized.

Show comment Hide comment
@aaronsw

aaronsw Oct 2, 2012

Contributor

Can you submit this as a pull request?

Contributor

aaronsw commented Oct 2, 2012

Can you submit this as a pull request?

@benhoyt

This comment has been minimized.

Show comment Hide comment
@benhoyt

benhoyt Oct 4, 2012

Contributor

Done here. Decided against putting v.keys()/keys in the error message as it gets kinda long. Closing this.

Contributor

benhoyt commented Oct 4, 2012

Done here. Decided against putting v.keys()/keys in the error message as it gets kinda long. Closing this.

@benhoyt benhoyt closed this Oct 4, 2012

bfdream pushed a commit to bfdream/webpy that referenced this issue Mar 24, 2014

Fix issue 183 as a pull request
Fixes unhelpful "Bad data" error message as per [issue 183](webpy/webpy#183).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment