On Jul 25, 3:59 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Jul 25, 2008 at 6:42 AM, [EMAIL PROTECTED] <
>
>
>
> [EMAIL PROTECTED]> wrote:
>
> > On Jul 24, 3:24 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> > wrote:
> > > 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?
>
> > 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?
>
> 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.
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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---