Problem with list containing dictionary

142 views
Skip to first unread message

GogiJan

unread,
Aug 11, 2010, 12:51:07 PM8/11/10
to MongoKit
Hello. I'm trying to use mongokit for validation of the following
structure:

class Test(TesterDocument):
collection_name = 'tests'
structure = {
'questions': [{
'header': unicode,
'answers': [{
'answerText': unicode,
# 'points': OR(int, [int]),
'points': int,
'position': int
}],
'position': int
}]
}
required_fields = [
'title', 'scales', 'questions'
'questions.$list.header', 'questions.$list.questionText',
'questions.$list.answers', 'questions.$list.answers.
$list.answerText'
]
}

And it is fails during connection.register(Test) with following error
message:
ValueError: Error in required_fields: can't find questions in
structure

If I uncomment #OR string then it fails with:
AttributeError: 'list' object has no attribute '__name__'

I think the problem is with lists containing dictionaries, or am I
doing something wrong?
Does somebody has recommendations on lists containing dictionaries in
mongokit?

Regards,
George Fatkin.

Nicolas Clairon

unread,
Aug 12, 2010, 5:23:14 AM8/12/10
to mong...@googlegroups.com
Hi,

You're right, this is a bug. It will be fixed in the version 0.6.

For the time beeing, I suggest you to overwrite the `validate` method
and check if the field `questions` is not empty:

def validate(self, *args, **kwargs):
assert len(self['questions']), 'self.questions is required'
super(Test, self).validate(*args, **kwargs)

If all goes well, I expected the release of version 0.6 in two week maximum.

N.

Ian L.

unread,
Aug 26, 2010, 3:38:49 AM8/26/10
to MongoKit

Ian L.

unread,
Sep 9, 2010, 12:37:41 AM9/9/10
to MongoKit
Hi Nicolas,

I noticed a commit[1] a few weeks ago that might have fixed this. Any
chance a fix for this could be in 5.10 instead of waiting for 6.0?

1. http://bitbucket.org/namlook/mongokit/changeset/996f56997b26

On Aug 12, 2:23 am, Nicolas Clairon <clai...@gmail.com> wrote:

Mark M

unread,
Sep 13, 2010, 6:53:21 AM9/13/10
to MongoKit
In 0.5.10 I am using a list that contains a dictionary. Try it now
with the new version. It might work.

Mark
structure = {'result': [{'fname': unicode,'gsingle': gsingle.GSingle,
'ghessian': ghessian.GHessian,}]
}


On Sep 9, 6:37 am, "Ian L." <ian.langwo...@gmail.com> wrote:
> Hi Nicolas,
>
> I noticed a commit[1] a few weeks ago that might have fixed this. Any
> chance a fix for this could be in 5.10 instead of waiting for 6.0?
>
> 1.http://bitbucket.org/namlook/mongokit/changeset/996f56997b26

Nicolas Clairon

unread,
Oct 19, 2010, 11:22:36 AM10/19/10
to mong...@googlegroups.com
Hi,

This feature will completely change the way of how MongoKit work. On
the source code and on the usability. So I shall not integrate it in
0.5.x

Anyway, when 0.6 will be out, it will be very, highly recommended to
migrate to 0.6.x. The branch 0.5.x will be here only for a smoother
migration.

N.

Reply all
Reply to author
Forward
0 new messages