Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#2167 closed defect (invalid)

Strings from pre-save trigger not quoted in Postgre

Reported by: Dagur Páll Ammendrup Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have this trigger in my model:

        def save(self):
            self.body_rest= publish_parts(self.body, writer_name='html4css1')['fragment']

It uses reST on the 'body' field and puts the output into the body_rest. This works fine with MySQL but if I try this on a server using PostgreSQL I get this error:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/" in _checklogin
  54. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/views/decorators/" in _wrapped_view_func
  40. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/" in change_stage
  330. new_object =
File "/usr/lib/python2.4/site-packages/django/db/models/" in save
File "/home/dagur/sytes/blog/" in save
  51. super(Post, self).save()
File "/usr/lib/python2.4/site-packages/django/db/models/" in save
  169. db_values + [pk_val])
File "/usr/lib/python2.4/site-packages/django/db/backends/" in execute
  12. return self.cursor.execute(sql, params)

  ProgrammingError at /admin/blog/post/1/
  ERROR: syntax error at or near "=<" at character 213 UPDATE "blog_post" SET "slug"='do-i-have-blog-again',"category_id"='general-nonsense',"title"='Do I have a blog again?',"date"='2006-06-14 00:42:00',"image"='',"body"='It looks like it. More later...',"body_rest"=<p>It looks like it. More later...</p> ,"publish"=True WHERE "id"='1'

As you can see the text is quoted for the 'body' field but not the 'body_rest' field, causing a syntax error.

Change History (2)

comment:1 Changed 12 years ago by Dagur <dagurp@…>

Version: SVN

comment:2 Changed 12 years ago by Adrian Holovaty

Resolution: invalid
Status: newclosed

That's happening because your assignment of self.body_rest is a Unicode string. Call the method .encode('utf8') on it to solve your problem.

Note: See TracTickets for help on using tickets.
Back to Top