From ee2af6bd1ed15a01952077a5c5f0e2f626eda4c6 Mon Sep 17 00:00:00 2001 From: Ivan Rocha Date: Mon, 9 Jun 2014 01:34:06 -0300 Subject: [PATCH] Avoiding TypeError when raw sql and no params sql = u'SELECT (strftime(\'%Y%W\', datetime)) AS "week", AVG("core_expense"."amount") AS "average", SUM("core_expense"."amount") AS "total" FROM "core_expense" GROUP BY strftime(\'%Y%W\', datetime), (strftime(\'%Y%W\', datetime)) ORDER BY "week" ASC' params = () When we try raw SQL queries like the one above, mainly when using builtin sql functions of the dbms, and devserver tries to print the queries, we get a "TypeError: not enough arguments for format string" --- devserver/modules/sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devserver/modules/sql.py b/devserver/modules/sql.py index 16ec0b7..454e304 100644 --- a/devserver/modules/sql.py +++ b/devserver/modules/sql.py @@ -64,7 +64,7 @@ class DatabaseStatTracker(DatabaseStatTracker): logger = None def execute(self, sql, params=()): - formatted_sql = sql % (params if isinstance(params, dict) else tuple(params)) + formatted_sql = params and sql % (params if isinstance(params, dict) else tuple(params)) or sql if self.logger: message = formatted_sql if settings.DEVSERVER_FILTER_SQL: