On Tue, Jun 15, 2010 at 8:31 PM, Chris Killpack <killp...@gmail.com> wrote:

> Hi Nick,
>
> I'm a little confused - I pass in the parent instance when I create a
> new AnalyticsCounter inside the transaction closure, so it should be
> part of the same group. See the 'if counter is None' path in my code
> snippet.  Did I miss something? I removed the transaction and using
> the datastore viewer and logging output, verified that the created
> entity's parent key matched the parent key I was creating. I'll try
> and post some of this to the thread later.
>

Your sample code reads:

> > self._parent_key = db.Key.from_path('AnalyticsCounter', 'virtual_root')
> > self._parent_instance = AnalyticsCounter.get_or_insert(key_name='root')

It looks like you're trying to modify the parent of an entity after it's
created here. This isn't possible, and in any case you shouldn't be directly
modifying internal properties of the model - nor should you be reading them
in the transaction - use self.parent() instead.

If this isn't what you're trying to do, can you provide  your exact
problematic code, including where you create the entities?

-Nick Johnson


> Thanks for the QPS limit advice - I only plan on updating < 10
> entities every hour, so I'm hoping this isn't an issue. Technically I
> don't really need to use a transaction, so I can always remove it, but
> I'm stubborn dammit and this should work :)
>
> Chris
>
> On Jun 15, 1:15 am, "Nick Johnson (Google)" <nick.john...@google.com>
> wrote:
> > Hi Chris,
> >
> > You need to specify the parent at creation time. There's no way to modify
> > the parent of an entity after it's created.
> >
> > Bear in mind that updates to an entity group are limited to roughly 1QPS
> -
> > so putting all your entities in one entity group is rarely a good idea.
> >
> > -Nick Johnson
> >
> >
> >
> >
> >
> > On Tue, Jun 15, 2010 at 4:12 AM, Chris Killpack <killp...@gmail.com>
> wrote:
> > > I have a set of entities all of the same kind, AnalyticsCounter, in my
> > > datastore. For correctness I would like to update many of these
> entities in
> > > a single transaction, which requires they are all in the same entity
> group.
> > > In my case I don't have a hierarchy, instead I just have a set of
> entities.
> > > My understanding is that I need to parent all of them to another
> > > AnalyticsCounter entity to achieve this. However when I tried this, I
> > > received the fateful "Cannot operate on different entity groups in a
> > > transaction error.".
> >
> > > I created the parent entity in my constructor, and then applied the
> parent
> > > when I created an instance of AnalyticsCounter, but the transaction
> fails on
> > > the put method. Interestingly the "different entity groups" lists both
> the
> > > newly created instance and the parent instance. I tried creating the
> parent
> > > two different ways, first just creating a key:
> > > self._parent_key = db.Key.from_path('AnalyticsCounter', 'virtual_root')
> > > and then, creating an actual instance.
> > > self._parent_instance = AnalyticsCounter.get_or_insert(key_name='root')
> > > but met the same failure on both cases.
> >
> > > Briefly, my transaction looks like this:
> > > counters = [list of key_names]
> > > def txn():
> > >   counters = AnalyticsCounter.get_by_key_name(counters)
> > >   for counter in counters:
> > >     if counter is None:
> > >       counter = AnalyticsCounter(parent=self._parent_instance,
> > > key_name='blah')
> > >       counter.foo = 'bar'
> > >     counter.put()  # <- dies here
> > > db.run_in_transaction(txn)
> >
> > > Can someone shed some light on what I am doing wrong? Thanks,
> >
> > > Chris
> >
> > > --
> > > 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<google-appengine%2bunsubscr...@googlegroups.com><google-appengine%2Bunsubscrib
> e...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine?hl=en.
> >
> > --
> > Nick Johnson, Developer Programs Engineer, App Engine Google Ireland Ltd.
> ::
> > Registered in Dublin, Ireland, Registration Number: 368047
> > Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration
> Number:
> > 368047
>
> --
> 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-appeng...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine+unsubscr...@googlegroups.com<google-appengine%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>


-- 
Nick Johnson, Developer Programs Engineer, App Engine Google Ireland Ltd. ::
Registered in Dublin, Ireland, Registration Number: 368047
Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number:
368047

-- 
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-appeng...@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