0

我只在生产中收到以下错误:BadRequestError: BLOB, ENITY_PROTO or TEXT properties must be in a raw_property field

它发生在我 put() Receipt 类的一个实例(扩展 ndb.Model)时

下面,我附上代码中断的模型和处理程序(仅在生产中)

class Receipt(RModel):
    ownerId = ndb.IntegerProperty()
    houseId = ndb.IntegerProperty()
    renterId = ndb.IntegerProperty()

    year = ndb.IntegerProperty()
    month_number = ndb.IntegerProperty()

    code = ndb.StringProperty()
    description = ndb.StringProperty()
    value = ndb.StringProperty()

    owner = ndb.ComputedProperty(lambda self: Owner.get_by_id(self.ownerId))
    house = ndb.ComputedProperty(lambda self: House.get_by_id(self.houseId))
    renter = ndb.ComputedProperty(lambda self: Renter.get_by_id(self.renterId))
    month = ndb.ComputedProperty(lambda self: month_number_to_string(self.month_number))


class RModel(ndb.Model):
    created = ndb.DateTimeProperty(auto_now_add = True)
    changed = ndb.DateTimeProperty(auto_now_add = True)
    creatorId = ndb.IntegerProperty()
    changerId = ndb.IntegerProperty()

    #def to_dict(self):
    #   return ndb.to_dict(self, {'id':self.key().id()})

    def set_attributes(self, **attrs):
        props = self.properties()
        for prop in props.values():
            if prop.name in attrs:
                prop.__set__(self, attrs[prop.name])


class ReceiptNew(BaseHandler):
    def Get(self):
        user_id = self.get_user_id()
        owner = Owner.get_by_id(user_id)
        receipt = Receipt(value="")
        houses = list(House.gql("where ownerId = :1", owner.key.id()))
        renters = list(Renter.gql("where ownerId = :1", owner.key.id()))
        context = {'receipt': receipt, 'houses': houses, 'renters': renters, 'new': True}
        self.render_response('receipt-edit.html', **context)

    def post(self):
        user_id = self.get_user_id()
        owner = Owner.get_by_id(user_id)

        data = {
            'year': self.request.get('year'),
            'month': self.request.get('month'),
            'house': self.request.get('house'),
            'renter': self.request.get('renter'),
            'value': self.request.get('value'),
            'paid': self.request.get('paid')
        }

        receipt = Receipt()
        receipt.year = int(data.get('year'))
        receipt.month_number = int(data.get('month'))
        receipt.houseId = int(data.get('house'))
        receipt.renterId = int(data.get('renter'))
        receipt.value = data.get('value')
        receipt.ownerId = owner.key.id()
        receipt.put() ##### CODE BREAKS HERE, ONLY IN PRODUCTION
        self.redirect('/receipts')
4

1 回答 1

2

您不能使用 ComputedProperty 来存储整个实体,您需要使用KeyProperty

于 2012-07-04T07:46:11.693 回答