Opened 9 years ago

Last modified 9 years ago

#25638 closed Bug

update using Concat with Value causes error-encoding in SQLite — at Version 3

Reported by: Bear Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8
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 (last modified by Tim Graham)

Suppose we want to concat a string to the end of a Charfield.
If we use:

  Model.objects.update(field=Concat('field', Value("end")))`

it will commit successfully, but the field will inlcude error-encoding text in SQLite. If we select the field from db, db will say "OperationalError: Could not decode to UTF-8 column 'name' with text".

Instead,

  Model.objects.update(field=Concat('field', Value("end"), None))

it will be OK.

Change History (3)

comment:1 by Tim Graham, 9 years ago

This test added to tests/db_functions/tests.py passes for me:

def test_concat_update(self):
    author = Author.objects.create(name='Jay')
    Author.objects.update(name=Concat('name', Value('end')))
    author.refresh_from_db()
    self.assertEqual(author.name, 'Jayend')

Can you provide a failing test or clarify the steps to reproduce?

comment:2 by Simon Charette, 9 years ago

@timgraham did you try setting the initial value of name and/or the Value() to a string with non-ASCII characters?

comment:3 by Tim Graham, 9 years ago

Description: modified (diff)

No trouble with this either:

def test_concat_update(self):
    author = Author.objects.create(name='Jὀy')
    Author.objects.update(name=Concat('name', Value('eὀd')))
    author.refresh_from_db()
    self.assertEqual(author.name, 'Jὀyeὀd')
Note: See TracTickets for help on using tickets.
Back to Top