Possible bug with full_clean in forms.py

21 views
Skip to first unread message

alaas...@terra.net.lb

unread,
Jul 24, 2008, 8:24:58 AM7/24/08
to Django developers
Hi all,

I think i stumbled over a bug. And i wanted to know if this a known
issue or not..a search here and in the bug db revealed nothing.

Calling full_clean in forms.py with a ModelChoiceField results in an
sql error because it isn't checking if the field is of this type
before using its value in the sql statement. The sql will fail with
"Error binding parameter 0 - probably unsupported type"

Has anyone seen this before?

alaas...@terra.net.lb

unread,
Jul 25, 2008, 6:42:27 AM7/25/08
to Django developers
On Jul 24, 3:24 pm, "alaasal...@gmail.com" <alaasal...@terra.net.lb>
wrote:
Actually, I'd like to revisit this. I believe the bug is in widgets.py
and the fact that the Select widget, when used for a ForeignKey, will
return incorrect data(the model instance as opposed to actual value).

I faced this issue trying to get django-rest-interface to work with
newforms, and so the serializer is returning the correct model, but
when getting the form for this model and trying to validate it, it
will cause this problem.

I think the fix is simple enough, if i understand this correctly. Any
input?

Karen Tracey

unread,
Jul 25, 2008, 8:59:50 AM7/25/08
to django-d...@googlegroups.com

A small test case illustrating the problem would help here.  There's plenty of code that uses the Select widget for ForeignKeys and doesn't run into trouble.  So I suspect something else is going on here, but on the information provided so far it is hard to be sure.

Karen

alaas...@terra.net.lb

unread,
Jul 25, 2008, 9:31:42 AM7/25/08
to Django developers


On Jul 25, 3:59 pm, "Karen Tracey" <kmtra...@gmail.com> wrote:
> On Fri, Jul 25, 2008 at 6:42 AM, alaasal...@gmail.com <
Well, the offending code exists in django-rest-interface and so this
might be a problem there after all. However, i tracked it down to
django itself by using the steps that i outlined above.

I will paste the code, i know its hard to "talk" about code but the
gist of the idea is that the django-rest-interface is deserializing
JSON data with a Foreign key. And then it is trying to create a form
out of the deserialized data and then
trying to validate it by "is_valid"

The culprit code is at http://dpaste.com/67388/
For some context, create calls get_data, and the request will contain
the JSON data. The JSON data is very simple, mine looks like this:

[{
"pk": 30,
"model": "fmdisplay.weatherstationsample",
"fields": {
"wind_speed": 0.0,
"light_intensity_sensor": 1.0,
"sample_time": "2008-06-24 17:19:25",
"wind_direction": 1.0,
"humidity_sensor": 1.0,
"weather_station": 4,
"temp_sensor": 1.0,
"precepitation_sensor": 1.0
}
}]

The weather_station field here is the one that corresponds to a
foreign key if that helps.

I also understand what you said about plenty of code using this, which
is why i found it strange. At first i assumed it was a django-rest-
interface since that project seems to be abandoned and i am trying to
make it run on trunk. Looking deeply into this, maybe its a newforms
issue...i am not sure.
Reply all
Reply to author
Forward
0 new messages