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.
--
Ticket URL: <https://code.djangoproject.com/ticket/25638>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/25638#comment:1>
Comment (by charettes):
@timgraham did you try setting the initial value of `name` and/or the
`Value()` to a string with non-ASCII characters?
--
Ticket URL: <https://code.djangoproject.com/ticket/25638#comment:2>
Old description:
> 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.
New description:
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.
--
Comment (by timgraham):
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')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25638#comment:3>
* status: new => closed
* resolution: => needsinfo
--
Ticket URL: <https://code.djangoproject.com/ticket/25638#comment:4>