Git Product home page Git Product logo

Comments (7)

jiangtao avatar jiangtao commented on July 22, 2024

求升级npm - - !

from thinkjs.

jiangtao avatar jiangtao commented on July 22, 2024

此问题还是存在.
Node版本:5.0.0
用于rest controller中

export default class extends think.controller.rest {
    /**
     * init
     * @param  {Object} http []
     * @return {}      []
     */
    init(http) {
        super.init(http);
    }

    /**
     * before magic method
     * @return {Promise} []
     */
    __before() {

    }

    async getAction() {
        let User = this.model('user');
        let query = this.http.query;
        try {

            let is = await User.checkExist(query.username);
            if (is) {
                this.success({msg: 'have'});
            } else {
                let id = await User.add(query);
                console.log(id)
                this.success({id: id});
            }
        } catch (e) {
            this.fail(e.message);
        }

    }

}

测试了多次,当model里面有add,delete等模型操作会引起 循环引用。

from thinkjs.

welefen avatar welefen commented on July 22, 2024

能把详细的错误信息提供下么?

from thinkjs.

jiangtao avatar jiangtao commented on July 22, 2024

可以的。
复现也特别容易就是在model里面 定义方法的时候 使用add等关键字字段

user model代码:

// XXX: 模型操作add关键字会引起循环引用
    add(query) {
        return this.add({
            username: query.username,
            password: think.md5(query.password),
            status: STATUS.ACTIVATED,
            timestamp: new Date().getTime()
        })
    }

引用代码就是上面的代码

export default class extends think.controller.rest {
    /**
     * init
     * @param  {Object} http []
     * @return {}      []
     */
    init(http) {
        super.init(http);
    }

    /**
     * before magic method
     * @return {Promise} []
     */
    __before() {

    }

    async getAction() {
        let User = this.model('user');
        let query = this.http.query;
        try {

            let is = await User.checkExist(query.username);
            if (is) {
                this.success({msg: 'have'});
            } else {
                let id = await User.add(query);
                console.log(id)
                this.success({id: id});
            }
        } catch (e) {
            this.fail(e.message);
        }

    }

}

报错消息:

{"errno":1000,"errmsg":"Maximum call stack size exceeded"}

避免发生:
把add等关键字改成非关键字即可。

from thinkjs.

welefen avatar welefen commented on July 22, 2024

你定义的方法名是 add,里面又调用了 add 方法,这样肯定会死循环啊。

from thinkjs.

welefen avatar welefen commented on July 22, 2024

定义的方法名不要和框架提供的方法名相同,不然的话会冲掉框架提供的方法。

from thinkjs.

jiangtao avatar jiangtao commented on July 22, 2024

可不可以在命令行 提供模型方法的列表 或者 必要的说明 或 log信息 。
因为常见的命名很容易冲突, 排查起来比较困难。

from thinkjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.