From 29d216021375446223a36901ab0ec60b6e3eadf9 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 25 Aug 2008 04:13:27 +0000 Subject: [PATCH] Fixed #7464 -- Fixed the psycopg2 backend to handle SafeString values as parameters. Based on a patch from Digitalxero@gmail.com. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8532 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/postgresql_psycopg2/base.py | 3 ++- tests/modeltests/field_defaults/models.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index b50cb1d1c9..61e440f577 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -10,8 +10,8 @@ from django.db.backends.postgresql.client import DatabaseClient from django.db.backends.postgresql.creation import DatabaseCreation from django.db.backends.postgresql.version import get_version from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection +from django.utils.safestring import SafeUnicode, SafeString -from django.utils.safestring import SafeUnicode try: import psycopg2 as Database import psycopg2.extensions @@ -23,6 +23,7 @@ DatabaseError = Database.DatabaseError IntegrityError = Database.IntegrityError psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) +psycopg2.extensions.register_adapter(SafeString, psycopg2.extensions.QuotedString) psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString) class DatabaseFeatures(BaseDatabaseFeatures): diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py index fe80cce406..18afb72a93 100644 --- a/tests/modeltests/field_defaults/models.py +++ b/tests/modeltests/field_defaults/models.py @@ -49,8 +49,10 @@ u'Default headline' >>> d.seconds < 5 True -# make sure that SafeUnicode fields work ->>> from django.utils.safestring import SafeUnicode +# make sure that SafeString/SafeUnicode fields work +>>> from django.utils.safestring import SafeUnicode, SafeString >>> a.headline = SafeUnicode(u'SafeUnicode Headline') >>> a.save() +>>> a.headline = SafeString(u'SafeString Headline') +>>> a.save() """}