Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2167 closed defect (invalid)

Strings from pre-save trigger not quoted in Postgre

Reported by: Dagur Owned by: adrian
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: UI/UX:

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.

Attachments (0)

Change History (2)

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

  • Version set to SVN

comment:2 Changed 8 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.