Django — str has no attribute default_alias

Jebus, it took me a long time to debug this since it was in an AJAX call and I assumed the source was from something else.

This is an error thrown when you pass in a string to an aggregation function.

objects.annotate('field') # fails with default_alias error.
objects.annotate(Sum('field')) # success

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