Opened 19 years ago

Closed 19 years ago

Last modified 18 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: dev
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

Description

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/base.py" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py" in _checklogin
  54. return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  40. response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/main.py" in change_stage
  330. new_object = manipulator.save(new_data)
File "/usr/lib/python2.4/site-packages/django/db/models/manipulators.py" in save
  101. new_object.save()
File "/home/dagur/sytes/blog/models.py" in save
  51. super(Post, self).save()
File "/usr/lib/python2.4/site-packages/django/db/models/base.py" in save
  169. db_values + [pk_val])
File "/usr/lib/python2.4/site-packages/django/db/backends/util.py" 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 by Dagur <dagurp@…>, 19 years ago

Version: SVN

comment:2 by Adrian Holovaty, 19 years ago

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