SkygearIO / py-skygear

Skygear Cloud Code Python SDK
https://skygear.io
Other
8 stars 20 forks source link

Add Lambda support for Skygear Data Type #201

Closed cheungpat closed 6 years ago

cheungpat commented 6 years ago

connects #195

carmenlau commented 6 years ago

When I try sending record to lambda created by py-skygear, lambda fail to parse the request with key error _ownerID.

Traceback (most recent call last):
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/transmitter/common.py", line 41, in wrapper
    return dict(result=f(self, *args, **kwargs))
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/transmitter/common.py", line 101, in call_func
    return self.op(obj, param.get('args', {}))
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/transmitter/common.py", line 171, in op
    kwargs = deserialize_value(param)
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 48, in deserialize_value
    return _RecordDecoder().decode_value(value)
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 142, in decode_value
    return self.decode_dict(v)
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 121, in decode_dict
    return {k: self.decode_value(v) for k, v in d.items()}
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 121, in <dictcomp>
    return {k: self.decode_value(v) for k, v in d.items()}
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 140, in decode_value
    return self.decode_record(v)
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 168, in decode_record
    return self.decode(d['$record'])
  File "/Users/carmenlau/work/skygear/py-skygear/skygear/encoding.py", line 62, in decode
    owner_id = d['_ownerID']
KeyError: '_ownerID'
cheungpat commented 6 years ago

can you write down the methodology you come to this error? I have seen this error before and I tested with this problem in mind, so it would be great if you state which SDKs/Platforms you come to this error and cloud code if any. Thanks!

carmenlau commented 6 years ago

@cheungpat

py cloud function

@skygear.op('test_record')
def test_record():
    task_record = {
        '_id': 'article/' + 'python',
        'content': 'Complete the sales report'
    }

    master_container = SkygearContainer(
        api_key=skyoptions.masterkey,
        user_id=current_user_id()
    )
    result = master_container.send_action(
        'record:save',
        {
            'database_id': '_public',
            'records': [task_record],
        }
    )
    return [
        1,
        2,
        True,
        "hello",
        Location(1, 2),
        result,
        {
            'location': Location(1, 2)
        }
    ]

In JS client

function lambdaTest() {
  var _type = "article";
  var _id = "js-to-python";
  var record = new skygear.Record(_type, {
    _id: _type + '/' + _id
  });
  record["content"] = 'js-to-python';
  skygear.publicDB.save(record).then(function(savedRecord){
    console.log("savedRecord");
    return skygear.lambda('test_record', {'oldNote': savedRecord, 'date': new Date()});
  }).then(response => {
    console.log(response);
  }, function (error) {
    console.log(error);
  });
};
cheungpat commented 6 years ago

@carmenlau which version of skygear-server are you running this pull request with?