Data integrity -  I want this to be atomic..   I do not want either A
or the list of B's saved if the other fails to save.

On Mar 19, 3:16 pm, djidjadji <djidja...@gmail.com> wrote:
> Why do you need a transaction for this operation?
> To create B objects that are children of some A  use
>
> a=A()
> a.put()  # create the parent object
> bObjs = [B(parent=a, somestring=s) for s in somelist]
> db.put(bObjs)
>
> 2009/3/19 Anonymous Coderrr <greedw...@gmail.com>:
>
>
>
>
>
> > Hi,
>
> > The documentation for entity-groups and transactions say that entities
> > must all be in the same eneity group for transaction operations to
> > work.  But it does not specifically say how to put entities in the
> > same entity group, other than some mention of setting the same parent,
> > which it also does not say how to do.
>
> > Maybe someone could show me specifically how to do this?
>
> > Let's say I have:
>
> > class A(db.Model):
> >    bList = db.ListProperty(db.Key)
>
> > class B(db.Model):
> >    someString = db.StringProperty()
>
> > def tran(self, a, bList):
> >        bKeys = put_each_list_item_return_keys_as_list(bList) # this
> > just calls put() on each item, returns keys
> >        a.bList = bKeys
> >        a.put()
>
> > # the work
> >        bLIst = createListofBs()
> >        a  = A()
> >        db.run_in_transaction(tran, a, bList)
>
> > If I run this, I get this error while the items in the bList are being
> > put:
>
> > BadRequestError: Cannot operate on different entity groups in a
> > transaction: (kind=u'B', id=65L) and (kind=u'B', id=None).
>
> > How do I get everything into one entity group so this transaction will
> > commit?
>
> > Thanks.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to