开发者

Django - Caught ValueError while rendering: list.remove(x): x not in list

开发者 https://www.devze.com 2023-03-11 19:45 出处:网络
I have category field in my form: category= forms.ModelChoiceField(queryset=Category.objects.all().filter(parentCat=None),

I have category field in my form:

category  = forms.ModelChoiceField(queryset=Category.objects.all().filter(parentCat=None),
                        widget = forms.Select(attrs = { 
                                                      'onchange' : "catChanged(this);", 
                                       )
                                                )              
                                                   }                                                                            

before I added a filter, all was fine. Then I added a filter to query all the categories that have parentCat = None. I now get this error:

Exception Type: TemplateSyntaxError Exception Value: Caught ValueError while rendering: list.remove(x): x not in list

Error is on the template where category field is rendered: {{ form.category }}

<div style="position:relative" >   <label> {{ form.category.label }}:</label> {{ form.category }}</div>

Any ideas what is causing this issue?

update: Strange behavior. First tim开发者_如何学Goe, GET renders the form, all is well; if I refresh, the second time GET renders the form I get the above error. TO reproduce, I have to stop and restart the web server!


This error seems to be a bug in Django or query adaptation by non-rel.

The error occured in module backends.py - apparenlty there is an issue with querying for ForiegnKeys that are null -

the failing line was :

query.table_map[table_name].remove(alias) 

I changed it to

try:
  query.table_map[table_name].remove(alias)
except:
  pass

This change basically ignores any errors in that line. All works as expected now; although I'm not sure why the error occurred, this change seems to fix it.

0

精彩评论

暂无评论...
验证码 换一张
取 消