python 2.7 - Django error: invalid syntax (<unknown>, line 1) when iterating queryset -


i've been working django few months now, , simple google search takes care of of problems (usually link so). have come across can't find solution , baffling.

general error information:

request method: request url: localhost:8000/switch/1 django version: 1.4 exception type: syntaxerror exception value:
invalid syntax (, line 1) exception location: /usr/lib/python2.7/ast.py in parse, line 37 python executable: /usr/bin/python python version: 2.7.3

relevant view code

interfaces = interface.objects.filter(switch=switch) interfaces = sorted(interfaces, key=lambda x: x.name) interfaces = sorted(interfaces, key=lambda x: len(x.name)) interface_table = interfacetable(interfaces) 

relevant model code

class interface(models.model):     class meta:         app_label = "network_builder"  name = models.charfield(max_length=20) fullname = models.charfield(max_length=30) switch = models.foreignkey("switch", related_name='switch') physical_state = models.charfield(max_length=30, blank=true, null=true) ip_address = models.charfield(max_length=20, blank=true, null=true)  administrator_notes = models.textfield(max_length=200, blank=true)  access_vlan = models.foreignkey(vlan, related_name='access_vlan', blank=true, null=true) native_vlan = models.foreignkey(vlan, related_name='native_vlan', blank=true, null=true)  admin_mode = models.charfield(max_length=20, blank=true, null=true)  operational_mode = models.charfield(max_length=20, blank=true, null=true) admin_encapsulation = models.charfield(max_length=20, blank=true, null=true) operational_encapsulation = models.charfield(max_length=20, blank=true, null=true)  switchport_state = models.charfield(max_length=20, blank=true, null=true) negotiation = models.booleanfield(blank=true)  native_vlan_tagging = models.booleanfield(blank=true)  allowed_vlans_list = listfield(blank=true, null=true) allowed_vlans_string = models.charfield(max_length=100, blank=true, null=true) active_vlans = models.manytomanyfield(vlan, related_name='active_vlans', blank=true, null=true) unpruned_vlans = models.manytomanyfield(vlan, related_name='unpruned_vlans', blank=true, null=true)  protected = models.booleanfield() unicast_blocked = models.booleanfield() multicast_blocked = models.booleanfield() 

stack trace:

environment:   request method: request url: http://localhost:8000/switch/2  django version: 1.4 python version: 2.7.3 installed applications: ('django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.sites',  'django.contrib.messages',  'django.contrib.staticfiles',  'network_builder',  'django.contrib.admin',  'django_tables2') installed middleware: ('django.middleware.common.commonmiddleware',  'django.contrib.sessions.middleware.sessionmiddleware',  'django.middleware.csrf.csrfviewmiddleware',  'django.contrib.auth.middleware.authenticationmiddleware',  'django.contrib.messages.middleware.messagemiddleware')   traceback: file "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response   111.                         response = callback(request, *callback_args, **callback_kwargs) file "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view   20.                 return view_func(request, *args, **kwargs) file "/home/ellis/projects/network_builder/network_builder/views/switch/info_views.py" in switch_page   46.     interfaces = sorted(interfaces, key=lambda x: x.name) file "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __len__   87.             self._result_cache.extend(self._iter) file "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in iterator   301.                     obj = model(*row[index_start:aggregate_start]) file "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in __init__   300.                 setattr(self, field.attname, val) file "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/subclassing.py" in __set__   34.         obj.__dict__[self.field.name] = self.field.to_python(value) file "/home/ellis/projects/network_builder/network_builder/models/model_fields.py" in to_python   18.         return ast.literal_eval(value) file "/usr/lib/python2.7/ast.py" in literal_eval   49.         node_or_string = parse(node_or_string, mode='eval') file "/usr/lib/python2.7/ast.py" in parse   37.     return compile(source, filename, mode, pycf_only_ast)  exception type: syntaxerror @ /switch/2 exception value: invalid syntax (<unknown>, line 1) 

at line:

interfaces = interface.objects.filter(switch=switch) 

interfaces populated queryset (observable through pdb), try variable (including printing, iterating, or sorting seen in above code), error thrown. baffling part if toss call try:except:, variable "interfaces" usable should be.

has seen before, or have insight in how track down solution?

i didn't figure out. using ast in custom listfield (how create list field in django) somehow breaking queryset's iterablility


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -