How to enter the required property in GAE

I modified my object to have the new required property in v2. When I try to retrieve the v1 object from the data store, I get a BadValueError because v1 does not have the required property. What is the best way to introduce new required properties into existing data

+5
source share
2 answers

I would solve this problem using the mapreduce library .

First register the display device in mapreduce.yaml:

mapreduce:
- name: fixing required property
  mapper:
    input_reader: mapreduce.input_readers.DatastoreInputReader
    handler: your handler
    params:
    - name: entity_kind
      default: main.ModelV2

then define a function processto modify the entities:

from mapreduce import operation as op
def process(entity):
 if not entity.newproperty :
    entity.newproperty = None
 yield op.db.Put(entity)

, mapreduce - :

entities = ModelV2.all()
for entity in entities :
  if not entity.newproperty :
    entity.newproperty = None
    entity.put()
+6

, , ( - ), () . , "", .

API- API- AppEngine .

+3

All Articles