Once you do 
model2.put()
the exception will be raised as expected. There is no validation prior to 
attempting to store the data in datastore unless you'd like to manually 
create it.

I.e. to get the error you were looking for try the following code:

class SecondModel(ndb.Model):
    important_prop = ndb.StringProperty(required=True)


class FirstModel(ndb.Model):
    some_prop = ndb.StringProperty()

    some_other_prop = ndb.StructuredProperty(SecondModel, required=True)
    
    
def some_func():

    buggy = None # attention here

    model2 = SecondModel(important_prop=buggy)
    *model2**.put()*
    model1 = FirstModel(some_other_prop=model2)
    model1.put()
    return


The highlighter line is all that was added.

Thanks,
Mihail.

On Friday, October 24, 2014 8:04:13 AM UTC-5, Lapteuh wrote:
>
> Hello. Noticed a strange behavior in the library ndb. In my opinion it 
> looks like a bug.
>
> Example:
>
> class SecondModel(ndb.Model):
>     important_prop = ndb.StringProperty(required=True)
>
>
> class FirstModel(ndb.Model):
>     some_prop = ndb.StringProperty()
>
>     some_other_prop = ndb.StructuredProperty(SecondModel, required=True)
>     
>     
> def some_func():
>
>     buggy = None # attention here
>
>     model2 = SecondModel(important_prop=buggy)
>     model1 = FirstModel(some_other_prop=model2)
>     model1.put()
>     return 
>
>
> Despite the fact that the code does not need to work, he works. No 
> exception! '*required*' option in property '*important_prop*' from '
> *SecondModel*' just ignored.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/d/optout.

Reply via email to