﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25517	Concat() database function is not idempotent in SQLite	Warren Smith	Warren Smith	"When running on sqlite, with a `Concat()` expression used in the query, the `ConcatPair.coalesce()` method is called every time the SQL is generated. This is normal, expected, and AFAIK, correct behavior.

The problem is that `ConcatPair.coalesce()` is not idempotent. So, **//every//** time the SQL is generated, each expression within the {{{ConcatPair}}} instance is wrapped with an additional `COALESCE()` SQL function. If generated enough times, the SQL can reach a point where it will crash the sqlite query parser.

This problem may not manifest itself in a typical request/response context, as the SQL with the additional `COALESCE()` calls will work identically to the original and the SQL may not be re-generated a sufficient number of times to crash the parser.

However, in a long-running process (where this bug was found), it can be easily triggered. For example, say I have a ""base"" queryset with a `Concat()` within an `.annotate()`. I never actually evaluate this queryset, but I use it to construct other querysets which I do evaluate. Because all of these querysets share the same instance of `Query._annotations`, evaluating ANY of these querysets will add an additional level of `COALESCE()` to the SQL generated by the others.
"	Bug	assigned	Database layer (models, ORM)	master	Normal		concat coalesce sqlite		Unreviewed	0	0	0	0	0	0
