Hey Greg,
Assuming you are deleting the property definition from the Model,
then I think you can also use:
your_entity._entity.pop('property_to_delete', None)
It is shorter, and probably a little clearer.
Robert
On Tue, Apr 5, 2011 at 00:17, Greg <[email protected]> wrote:
> I've stumbled across what looks like a neat way to remove obsolete
> properties from entities, without having to switch models to Expando
> and back again. I convert the entity to a protocol buffer, which
> reveals the obsolete properties. Then I remove them, convert back to
> an entity and save it.
>
> So far my testing has shown this doesn't have any ill effects, but I'd
> like feedback in case what I'm doing is dangerous. In particular, I
> don't understand what would happen to the indexes for the removed
> properties - how does the datastore handle these?
>
> Cheers
> Greg.
>
> # !!! EXPERIMENTAL CODE !!!
> # !!! USE ENTIRELY AT YOUR OWN RISK !!!
> # !!! NOT ENDORSED BY GOOGLE (YET) !!!
>
> from google.appengine.ext import db
>
> def remove_stale_properties(e):
> current_properties=e.properties().keys()
> epb=db.model_to_protobuf(e)
> for i in reversed(range(len(epb.property_))):
> if epb.property_[i].name() not in current_properties:
> logging.info('Deleting property %s:%s'%
> (epb.property_[i].name(),epb.property_[i].value()))
> del epb.property_[i]
> for i in reversed(range(len(epb.raw_property_))):
> if epb.raw_property_[i].name() not in current_properties:
> logging.info('Deleting raw property %s:%s'%
> (epb.raw_property_[i].name(),epb.raw_property_[i].value()))
> del epb.raw_property_[i]
> return db.model_from_protobuf(epb)
>
> # Example usage
>
> entity_list=Foo.all().fetch(1000)
> for entity in entity_list:
> entity=remove_stale_properties(entity)
> db.put(entity_list)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.