Opened 7 years ago

Last modified 7 years ago

#29155 closed Bug

Using contains field lookup with Substr database function cause modification of second parameter of Substr — at Initial Version

Reported by: norac89 Owned by: nobody
Component: Database layer (models, ORM) Version: 2.0
Severity: Normal Keywords:
Cc: Mariusz Felisiak Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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%'.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top