#3115 closed defect (fixed)
Postgresql backend should convert Unicode input to bytestrings
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | major | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
ORM fails in PostgreSQL when you filter with unicode strings. For example:
>>> from django.contrib.auth.models import User >>> User.objects.filter(username=u'admin') ... ProgrammingError: ERROR: column "admin" does not exist SELECT "auth_user"."id","auth_user"."username","auth_user"."first_name","auth_user"."last_name","auth_user"."email","auth_user"."password","auth_user"."is_staff","auth_user"."is_active","auth_user"."is_superuser","auth_user"."last_login","auth_user"."date_joined" FROM "auth_user" WHERE ("auth_user"."username" = admin) ORDER BY "auth_user"."username" ASC
The problem is on psycopg library, here are an example:
>>> from django.db import connection >>> cursor = connection.cursor() >>> cursor.execute('SELECT * from auth_user WHERE username = %s', [u'admin']) ... ProgrammingError: ERROR: column "admin" does not exist SELECT * from auth_user WHERE username = admin
Ok, it's true... it's not a django error, but for example, in newforms all is unicode... ¿what we do? ¿Use psycopg2? ¿convert all unicodes to ascii in lookups? ¿convert all params on postgresql?. Call is made on django/db/models/query.py, on this sentences:
cursor = connection.cursor() select, sql, params = self._get_sql_clause() cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params)
Change History (5)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
Summary: | ORM problems with unicode in postgresql backend → Postgresql backend should convert Unicode input to bytestrings |
---|
comment:4 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Yes, we ought to change the postgresql Django database backend to check whether each string is Unicode before adding it to the statement.
This also ties into another suggestion people have had, which is to have a DATABASE_CHARSET setting. This would describe which character set the database uses.