AntonioM
AntonioM

Reputation: 655

Problems with StructuredProperty and StringProperty

i am doing the finally degree work in Google App Engine, but i am having problems when i try this:

class Predicate(ndb.Model):
    name = ndb.StringProperty()
    parameters = ndb.JsonProperty()

class State(ndb.Model):
    predicates = ndb.StructuredProperty(Predicate, repeated=True)

class Action(ndb.Model):
    name = ndb.StringProperty()
    parameters = ndb.StringProperty(repeated=True)
    preconditions = ndb.StructuredProperty(Predicate, repeated=True)
    predicatesToAdd = ndb.StructuredProperty(Predicate, repeated=True)
    predicatesToDel = ndb.StructuredProperty(Predicate, repeated=True)

class Plan(ndb.Model):
    plan = ndb.StructuredProperty(Predicate, repeated=True)

class Problem(ndb.Model):
    initialState = ndb.StructuredProperty(Predicate)
    goalState = ndb.StructuredProperty(Predicate)
    actions = ndb.StructuredProperty(Action, repeated=True)

i get this error:

TypeError: This StructuredProperty cannot use repeated=True because its model class (Predicate) contains repeated properties (directly or indirectly).

StructuredProperty, if it contains repetitions, can not be replicated another StructuredProperty. But I need this structure models. How can i solve this?

And sorry for my bad english :(


I solved this problem using LocalStructuredProperty, but I think it will not work at all

Upvotes: 1

Views: 372

Answers (1)

Gwyn Howell
Gwyn Howell

Reputation: 5424

The problem with your design is that ndb does not allow nested repeated properties. In other words, you cannot have a repeated structured property, which in turn has its own repeated property. If you remove the repeated=True from the parameters property, it will work.

You will need to re-think your design to work around this. One possible solution may be to use a JsonProperty for parameters, and store the list of strings as a JSON string. You won't be able to query them then of course, but it may work out depending on your requirements.

Upvotes: 1

Related Questions