[Django] #26468: Bug in models.functions.ConcatPair for sqlite

5 views
Skip to first unread message

Django

unread,
Apr 5, 2016, 5:45:59 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------+--------------------
Reporter: jerch | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Concat is not working for me due to this line in
models.functions.ConcatPair.coalesce:

{{{
Coalesce(expression, Value('')) for expression in
c.get_source_expressions()
}}}

With a minor change it works as intended:

{{{
Coalesce(expression, Value('""')) for expression in
c.get_source_expressions()
}}}

Tested with Django 1.8.12 under Ubuntu with sqlite 3.8.2-1ubuntu2.1.

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

Django

unread,
Apr 5, 2016, 5:55:59 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------+--------------------------------------

Reporter: jerch | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
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 shaib):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

When you say "not working for me" -- what did you give as inputs, what did
you expect to happen and what happened instead?

--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:1>

Django

unread,
Apr 5, 2016, 6:25:34 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------+--------------------------------------

Reporter: jerch | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
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 jerch):

I tried to concat to db fields into one output column like this:

{{{
expr = Concat(models.F('field1'), models.Value('"-"'), models.F('field2'),
outputfield=models.CharField())
}}}

Expected output: 'value_from_field_1-value_from_field_2'

Instead I just got an invalid syntax sql error.

--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:2>

Django

unread,
Apr 5, 2016, 6:52:17 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------------+-------------------------------------

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

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

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

* keywords: => sqlite concat
* component: Uncategorized => Database layer (models, ORM)


--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:3>

Django

unread,
Apr 5, 2016, 8:50:33 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------------+-------------------------------------

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

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

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

Comment (by jarshwah):

I can't reproduce:

{{{
In [6]: from django.db import connection

In [7]: connection.vendor
Out[7]: u'sqlite'

In [8]: concat = Concat(F('name'), Value('-'), F('motto'),
output_field=CharField())

In [9]: Company.objects.annotate(concat=concat).first().concat
Out[9]: u'HI-'

In [10]: concat = Concat(F('name'), Value('"-"'), F('motto'),
output_field=CharField())

In [11]: Company.objects.annotate(concat=concat).first().concat
Out[11]: u'HI"-"'

In [12]: import django

In [13]: django.get_version()
Out[13]: '1.10.dev20160401110429'
}}}

Note that I tried both Value('"-"') and Value('-'). You shouldn't be
injecting quotes into Value, it'll take care of itself.

Can you please post the full queryset you're running that generates the
error, and also print the underlying query of the queryset, like this:

{{{
qs = Model.objects.whatever()
print(qs.query)
}}}

Also, what version of Django are you using? Can you reproduce on master?

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

Django

unread,
Apr 5, 2016, 8:50:46 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------------+-------------------------------------

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

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

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

* cc: josh.smeaton@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:5>

Django

unread,
Apr 5, 2016, 8:56:42 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------------+-------------------------------------

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

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

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

Comment (by jarshwah):

Can't reproduce on stable 1.8 or 1.9 either.

--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:6>

Django

unread,
Apr 5, 2016, 11:17:15 PM4/5/16
to django-...@googlegroups.com
#26468: Bug in models.functions.ConcatPair for sqlite
-------------------------------------+-------------------------------------
Reporter: jerch | Owner: nobody
Type: Bug | Status: closed

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

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

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

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


Comment:

Please reopen if you can provide more details about your Django, Python
and SQLite3 version (`import sqlite3; sqlite3.version`).

--
Ticket URL: <https://code.djangoproject.com/ticket/26468#comment:7>

Reply all
Reply to author
Forward
0 new messages