﻿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
29155	Using contains lookup with Substr causes modification of second parameter of Substr	norac89	Mariusz Felisiak	"My model:


{{{
class User(models.Model):
    field1 = models.CharField(max_length=120)
    field2 = models.CharField(max_length=120)
}}}

Tried querying the model to get User instances in which field2 start with the three first characters of field1.
Tried the following:

{{{
User.objects.filter(field2__startswith=Substr(F('field1'), 1, 3))
}}}
  
I m getting the following error

{{{
psycopg2.DataError: invalid input syntax for integer: ""1%""
LINE 1: ...(REPLACE(REPLACE((SUBSTRING(""test_user"".""field1"", '1%', 3)),...
}}}

The second parameter of the substr function seems to be replaced with '1%'.
  "	Bug	closed	Database layer (models, ORM)	2.0	Normal	fixed		Mariusz Felisiak	Ready for checkin	1	0	0	0	0	0
