Django — ‘int’ object is not iterable

I was led on another wild goose chase bug hunting this in an ajax function that had heavily nested try/except blocks because it hid the real line number of the error.

For me, this was a simple error caused by passing an argument to myobject.get() without a keyword.

MyModel.objects.get(3)

This makes me want to explore more robust exception handling that pulls line numbers into the error message. I’m sure it would pay for itself in time.

try:
    MyModel.objects.get(3)

except Exception, e:
    log.debug("Exception {e} thrown on line {lineno}".format(
        e=e,
        lineno=sys.exc_info[2].tb_lineno,
    )
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s