[Django] #25638: update using Concat with Value causes error-encoding in SQLite

11 views
Skip to first unread message

Django

unread,
Oct 29, 2015, 7:31:13 PM10/29/15
to django-...@googlegroups.com
#25638: update using Concat with Value causes error-encoding in SQLite
----------------------------------------------+--------------------
Reporter: bearxu83 | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25638>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 30, 2015, 2:01:51 PM10/30/15
to django-...@googlegroups.com
#25638: update using Concat with Value causes error-encoding in SQLite
-------------------------------------+-------------------------------------

Reporter: bearxu83 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Oct 30, 2015, 2:29:48 PM10/30/15
to django-...@googlegroups.com
#25638: update using Concat with Value causes error-encoding in SQLite
-------------------------------------+-------------------------------------

Reporter: bearxu83 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Oct 30, 2015, 2:39:02 PM10/30/15
to django-...@googlegroups.com
#25638: update using Concat with Value causes error-encoding in SQLite
-------------------------------------+-------------------------------------

Reporter: bearxu83 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Oct 31, 2015, 5:58:23 PM10/31/15
to django-...@googlegroups.com
#25638: update using Concat with Value causes error-encoding in SQLite
-------------------------------------+-------------------------------------
Reporter: bearxu83 | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => needsinfo


--
Ticket URL: <https://code.djangoproject.com/ticket/25638#comment:4>

Reply all
Reply to author
Forward
0 new messages