Dec 28

'unicode' object has no attribute 'get_sql'

I keep getting this error, and it always takes a moment of head-scratching to figure out what's wrong. Here's what's wrong, to save you some hair.

Another tiny snippet for you.

You fire up your Django app, only to be confronted with:

AttributeError at /highwire/projects/1/tasks/add/
'unicode' object has no attribute 'get_sql'

You've probably got a line like this:

foo = get_object_or_404(Foo, foo_id)

get_object_or_404() actually requires key/value pairs after the first class argument, in the same way the .filter() method does.

The code above should actually read:

foo = get_object_or_404(Foo, pk=foo_id)

It's the simple things that eat the most time.

I've disabled comments for now due to spam problems - I'll turn them back on when I've fixed it!

This won't be published anywhere, it's just in case I need to contact you.

You can use Markdown in your comments. Be sensible!

Sorry about this, but I don't want spam comments.