lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

Iterating through ListField ot DictFields returns AnonymousStruct #69

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Have a ListField of DictField
2. iterate list and get individual dicts
3.

What is the expected output? What do you see instead?
I was expecting to get dictionaries, but instead I get AnonyomousStruct. I
can unwrap it do get my dict, but is that the right behaviour?

What version of the product are you using? On what operating system?
couchdb-python 0.5, couchdb 0.8

Please provide any additional information below.

Original issue reported on code.google.com by gilbert....@gmail.com on 31 Mar 2009 at 4:59

GoogleCodeExporter commented 8 years ago
I assume you had a DictField mapped to a Schema, e.g. something like

  mylist = ListField(DictField(Schema.build(
    foo = IntegerField(),
    bar = TextField()
  )))

In that case Schema.build actually creates a class, and the name of that class 
is AnonymousStruct. So I think 
what you're seeing here is expected. In fact, if you got plain dicts back, you 
couldn't do tricks like:

  print mylist[0].foo

If you just want a plain dict, you can create a DictField that isn't bound to a 
Schema:

  mylist = ListField(DictField)

Original comment by cmlenz on 29 Jun 2009 at 2:58