#29155 closed Bug (fixed)
Using contains lookup with Substr causes modification of second parameter of Substr
| Reported by: | norac89 | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| 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 (last modified by )
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%'.
Attachments (1)
Change History (8)
comment:1 by , 8 years ago
| Description: | modified (diff) |
|---|---|
| Summary: | Using contains field lookup with Substr database function cause modification of second parameter of Substr → Using contains lookup with Substr causes modification of second parameter of Substr |
| Triage Stage: | Unreviewed → Accepted |
by , 8 years ago
| Attachment: | 29155-test.diff added |
|---|
comment:2 by , 8 years ago
| Cc: | added |
|---|
comment:3 by , 8 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:5 by , 8 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
I'm attaching a test for Django's test suite that fails (on PostgreSQL but not SQLite) as of ba37ee9ef882deb8e917f1cae0c586a0a275e731.