ForestAdmin / forest-express-sequelize

🌱 Express/Sequelize agent for Forest Admin to integrate directly to your existing Express/Sequelize backend application.
https://www.forestadmin.com
GNU General Public License v3.0
190 stars 47 forks source link

TypeError: Cannot read property 'get' of null #211

Open jabm111 opened 5 years ago

jabm111 commented 5 years ago

Expected behavior

I have two models involved: guides and steps. I expect to be able to create a guide and create steps associated with that guide from the Forest Admin web interface. I sent this issue to support@forestadmin.com but I'm posting it here in case someone from the community has had a similar issue and might have a solution.

Actual behavior

I am able to create a guide but when I try to create a step associated with that guide no network request is made and an error is logged to the console. This error was not occurring the last time I tried it (September 19) and we've made no model/code changes in several months.

Steps to reproduce:

guides model:

"use strict";
module.exports = function(sequelize, DataTypes) {
    var guides = sequelize.define("guides", {
        title: {
            type: DataTypes.STRING,
            allowNull: true
        },
        subtitle: {
            type: DataTypes.STRING,
            allowNull: true
        },
        image: {
            type: DataTypes.STRING,
            allowNull: true
        },
        image_thumbnail: {
            type: DataTypes.STRING,
            allowNull: true
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: true
        },
        product_identifier: {
            type: DataTypes.STRING,
            allowNull: true
        },
        archive: {
            type: DataTypes.STRING,
            allowNull: true
        },
        reduced_mobility: {
            type: DataTypes.BOOLEAN,
            defaultValue: false,
            allowNull: false
        },
        language: {
            type: DataTypes.ENUM("fr", "en"),
            defaultValue: "fr",
            allowNull: false
        },
        credit_image: {
            type: DataTypes.STRING,
            allowNull: true
        },
        link: {
            type: DataTypes.STRING,
            allowNull: true
        },
        archive_size_string: {
            type: DataTypes.STRING,
            allowNull: true
        },
        archive_size_bytes: {
            type: DataTypes.INTEGER,
            allowNull: true
        },
        order: {
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: 1
        },
        autoplay: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: false
        },
        onsite_limit: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: false
        },
        environment: {
            type: DataTypes.ENUM("development", "staging", "production"),
            defaultValue: "development",
            allowNull: false
        },
        guide_type: {
            type: DataTypes.ENUM("navigation", "audio", "parcour"),
            defaultValue: "navigation",
            allowNull: false
        },
        is_free: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: false
        }
    });

    guides.associate = function(models) {
        guides.hasMany(models.steps);
        guides.belongsTo(models.locations, {
            foreignKey: "start_location_id",
            as: "start_location"
        });
        guides.belongsTo(models.locations, {
            foreignKey: "end_location_id",
            as: "end_location"
        });
    };

    return guides;
};

steps model:

'use strict';
module.exports = function(sequelize, DataTypes) {
    var steps = sequelize.define('steps', {
        order: {
            type: DataTypes.INTEGER,
            allowNull: true,
            validate: {
                min: 0,
            },
        },
        playlist_title: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        playlist_instruction: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        meta: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: true,
        },
        image: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        image_thumbnail: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        audio: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        guide_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: 'guides',
                key: 'id',
            },
        },
        step_type: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: 'other',
        },
        autoplay_group: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: 'none',
        },
        ext_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
        },
        ext_data: {
            type: DataTypes.TEXT,
            allowNull: true,
        },
        ext_updated_at: {
            type: DataTypes.STRING,
            allowNull: true,
        },
    });

    steps.associate = function(models) {
        steps.belongsTo(models.guides);
        steps.belongsToMany(models.beacons, { through: 'step_beacon' });
    }

    return steps;
};

Failure Logs

TypeError: Cannot read property 'get' of null
    at client-5fdff9cef7c56…54b566218f6.js:1177
    at o.forEach (vendor-039ff5e8d2118…4f25499893e.js:3532)
    at o.saveNewRecord (client-5fdff9cef7c56…54b566218f6.js:1176)
    at o.y (vendor-039ff5e8d2118…4f25499893e.js:3287)
    at d (vendor-039ff5e8d2118…4f25499893e.js:3932)
    at E.trigger (vendor-039ff5e8d2118…4f25499893e.js:4089)
    at o.send (vendor-039ff5e8d2118…4f25499893e.js:3323)
    at o.send (vendor-039ff5e8d2118…4f25499893e.js:3494)
    at o.triggerAction (vendor-039ff5e8d2118…4f25499893e.js:3600)
    at o.sendAction (vendor-039ff5e8d2118…4f25499893e.js:3759)

Context

Thanks!

arnaudbesnier commented 5 years ago

Hey @jabm111, Thank you for the feedback.

We've released a batch of fixes recently and your issue really looks like an issue we've fixed. Could you retry and let us know if we can close the issue?

Thanks.