Opened 15 years ago

Closed 10 years ago

#13383 closed Bug (duplicate)

Querysets should only allow the correct model types to be filtered against

Reported by: Chris Beaven Owned by:
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here's a simple example of what is allowed at the moment. It seems that this should throw an exception for the last line:

In [1]: from django.contrib.auth.models import *


In [3]: u = User.objects.all()[0]


In [5]: m = Message.objects.create(user=u, message='test')

In [6]: m.pk, u.pk
Out[6]: (1, 1)


In [10]: User.objects.filter(message=m)
Out[10]: [<User: chris_b>]

In [11]: User.objects.filter(message=u)
Out[11]: [<User: chris_b>]

Change History (12)

comment:1 by Alex Gaynor, 15 years ago

milestone: 1.3
Triage Stage: UnreviewedAccepted

comment:2 by anonymous, 15 years ago

Owner: changed from nobody to anonymous
Status: newassigned

It seems last line wil not throw an exception but returns empty list

u = User.objects.all()[0]
m = Message.objects.create(user=u, message='test')
m

<Message: test>

u

<User: admin>

User.objects.filter(message=m)

[<User: admin>]

User.objects.filter(message=u)

[]

comment:3 by Chris Beaven, 15 years ago

It depends on the primary key of your user, hence my line 6 output in the initial description showing they both have the id of 1

comment:4 by Aviral Dasgupta, 15 years ago

Owner: changed from anonymous to Aviral Dasgupta
Status: assignednew

comment:5 by Aviral Dasgupta, 14 years ago

Owner: Aviral Dasgupta removed

comment:6 by Hello Ok, 14 years ago

Owner: set to Hello Ok

comment:7 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:8 by Hello Ok, 14 years ago

Owner: Hello Ok removed

comment:9 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

comment:11 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:12 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:13 by Claude Paroz, 10 years ago

Resolution: duplicate
Status: newclosed

Fixed in #14334

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