简体   繁体   English

解析云功能失败,错误141

[英]Parse Cloud function fails with error 141

What I'm trying to accomplish is when I call this cloud function ( deploy ), it will first delete all data from toClass , then iterate over objects in fromClass , copy and save them to toClass . 我要完成的工作是,当我调用此云函数( deploy )时,它将首先从toClass删除所有数据,然后遍历fromClass对象,将其复制并保存到toClass When it saves an object, it will also delete it from fromClass . 保存对象时,也会从fromClass删除它。 Simply put, move the objects from class to another. 简而言之,将对象从类移动到另一个。 Calling this function on client 在客户端调用此函数

[PFCloud callFunctionInBackground:@"deploy" withParameters:@{@"toClass": kTilrClassUpdates, @"fromClass": kTilrClassPrototypeUpdates} block:^(id object, NSError *error) {
    if (error) {
        [self failed];
    } else {
        [self succeeded];
    }
}];

Will print this error message to client log: Error: undefined (Code: 141, Version: 1.2.19) 将此错误消息打印到客户端日志: Error: undefined (Code: 141, Version: 1.2.19)

Here is the code for Parse Cloud: 这是解析云的代码:

Parse.Cloud.define("deploy", function(request, response) {
    var query = new Parse.Query(request.params.toClass);
    query.find({
        success: function(results) {
            for (var i = 0; i < results.length; ++i) {
                console.log(results[i]);
                results[i].destroy({
                    success: function(object) {

                    },
                    error: function(object, error) {
                        response.error(error);
                    }
                });
            }
        },
        error: function() {
            response.error(error);
        }
    });
    var query2 = new Parse.Query(request.params.fromClass);
    query2.find({
        success: function(results) {
            for (var index = 0; index < results.length; ++index) {
                var UpdateInfoClass = Parse.Object.extend(request.params.toClass);
                var updateInfo = new UpdateInfoClass();
                for (var k in results[index]) {
                    updateInfo.set(k, results[index][k]);
                }
                console.log(updateInfo);
                updateInfo.save(null, {
                    success: function(updateInfo) {
                        results[index].destroy();
                        if (index == results.length - 1) {
                            response.success();
                        }
                    },
                    error: function(updateInfo, error) {
                        response.error(error);
                    }
                });
            }
        },
        error: function() {
            response.error(error);
        }
    });
});

I really don't know much about JavaScript, so this could be a very simple mistake somewhere. 我真的对JavaScript不太了解,所以在某个地方这可能是一个非常简单的错误。

There is couple of sections which can guarantee problems for you: While not questioning your design : 有几个部分可以为您保证出现问题:在不质疑您的设计的同时:

1) queries are not chained together and will run at the same 1)查询未链接在一起,并且将在同一时间运行

2) you cannot use 2)你不能使用

for (var k in results[index]) {
    updateInfo.set(k, results[index][k]);
}

to copy properties from one object to another. 将属性从一个对象复制到另一个对象。 You need to call JSON.stringify(results[index]) to get standard array. 您需要调用JSON.stringify(results[index])以获取标准数组。 You should set values by likes of request.object.set(fiedlName, value) . 您应该通过request.object.set(fiedlName, value)值来设置值。

3) "index" will not get propagated correctly into subblock - log it into console and you'll see, because also these queries are not chained up and it will run at once thus index will have some value or the last one because it is fast 3)“索引”将不会正确传播到子块中-将其登录到控制台中,您将看到,因为这些查询没有被链接起来,并且会立即运行,因此索引将具有某些值或最后一个值,因为它是快速

However , the design of your method is questionable : 但是,您的方法的设计值得怀疑:

Database on parse is a bit different from ordinary sql database , and you should perhaps redesign your method perhaps using one class and just marking object's class by name or changing their state (deployed = 0 / 1 ), it is hard to guess what are you trying to accomplish, but your way guarantees some problems. 解析数据库与普通sql数据库有些不同,您也许应该使用一个类重新设计您的方法,或者仅通过名称标记对象的类或更改其状态(部署= 0/1),就很难猜出您是什么尝试完成,但是您的方式可以保证出现一些问题。

Also note that cloudcode functions do have some timeout so once you have more objects you may not be able to save all of them. 还要注意,cloudcode函数确实有一些超时,因此一旦拥有更多对象,您可能将无法保存所有这些对象。 (150 objects is optimistic view) (150个对象是最佳视图)

You may achieve your solution by writing proper ".beforeSave" function which is triggered when you save your object, this way you can replace old object with new object based on your criteria... 您可以通过编写适当的“ .beforeSave”函数来实现您的解决方案,该函数在保存对象时触发,这样您可以根据自己的条件用新对象替换旧对象...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM