Keep getting "No change in apimap, nothing sent to Forest."

Feature(s) impacted

Re-generating the apimap when the local server re-starts

Observed behavior

After changing a field, creating an action, deleting a field, I keep getting this message: No change in apimap, nothing sent to Forest. Which then means that my changes doesn’t get added to forest-schema, and then cannot see any changes on the website.

Expected behavior

Apimap to be regenerated when making changes to a forest collection.

Context

  • Project name: fleks
  • Environment name: local
  • Agent (forest package) name & version: forest-express-sequelize: 8.5.14,
  • Database type: PostgreSQL

Hello @Alejandro_Salazar,

I can see in our database that the latest change on your development environment has been made on August 3rd.

Can you check that the environment secret configured on your development environment ends with 64f?

Also, can you provide us with the value of NODE_ENV? When its value is production, the schema is not automatically re-generated at startup.

Also, can you check the file .forestadmin-schema.json : does it contain your modifications?

Hi! thanks for your quick reply.

I can confirm my secret ends in 64f.

The value of NODE_ENV is ‘testing’ (which is our local value).

And finally, no, .forestadmin-schema.json doesn’t contain any modification.

Is there a way (command or something else) that I can use to re-generate the .forestadmin-schema.json by-passing the checks?

We will need to check every of these conditions, in order to find where the misconfiguration lies:

  1. Agent must be restarted for the changes to be added to the schema
  2. the environment variable NODE_ENV must not be equal to production
  3. the environment variable FOREST_DISABLE_AUTO_SCHEMA_APPLY must NOT be set
  4. the directory containing the configuration of collections, smart actions and smart fields must be correctly referenced as configDir when calling init (1)

Could you share the skeleton of the file where the action and field are configured, and make sure that this file is correctly loaded?

(1): here is an example of my configuration:

  // In my case, this code lies in middlewares/forestadmin.js
  const Agent = require('forest-express-sequelize');

  app.use(await Agent.init({
    modelsDir: path.join(__dirname, '../models'),
    // It references a directory in the root folder
    configDir: path.join(__dirname, '../forest'),
    envSecret: process.env.FOREST_ENV_SECRET,
    authSecret: process.env.FOREST_AUTH_SECRET,
    objectMapping: sequelize.Sequelize,
    connections: { default: sequelize },
  }));

And the directory forest contains configuration files, for instance

// Content of forest/posts.js
const { collection } = require('forest-express-sequelize');

// This file allows you to add to your Forest UI:
// - Smart actions: https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions
// - Smart fields: https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields
// - Smart relationships: https://docs.forestadmin.com/documentation/reference-guide/relationships/create-a-smart-relationship
// - Smart segments: https://docs.forestadmin.com/documentation/reference-guide/segments/smart-segments
collection('posts', {
  actions: [{
    name: 'do-something'
  }],
  fields: [],
  segments: [],
});

We are using an old version, so we haven’t really used Agent to set up forest. But this is roughly how our config files look:

const {
  ensureAuthenticated,
  PUBLIC_ROUTES,
} = require('forest-express-sequelize');

app.use(
  '/forest/authentication',
  cors({
    ...corsConfig,
    // The null origin is sent by browsers for redirected AJAX calls. We need to
    // support this in authentication routes because OIDC redirects to the
    // callback route
    origin: [...corsConfig.origin, 'null'],
  })
);

app.use(
  jwt({
    secret: process.env.FOREST_AUTH_SECRET,
    credentialsRequired: false,
  })
);

app.use('/forest', (request, response, next) => {
  if (PUBLIC_ROUTES.includes(request.url)) {
    return next();
  }
  return ensureAuthenticated(request, response, next);
});

requireAll({
  dirname: path.join(__dirname, 'routes'),
  recursive: true,
  resolve: Module => app.use('/forest', Module),
});

requireAll({
  dirname: path.join(__dirname, 'middlewares'),
  recursive: true,
  resolve: Module => Module(app),
});

The config file hasn’t been updated for 3 / 4 years, and we updated to forest-express-sequelize 8 a couple of months ago.

And this is our middleware folder:

const Liana = require('forest-express-sequelize');
const chalk = require('chalk');
const { objectMapping, connections } = require('../models');

module.exports = async function (app) {
  app.use(
    await Liana.init({
      envSecret: process.env.FOREST_ENV_SECRET,
      authSecret: process.env.FOREST_AUTH_SECRET,
      objectMapping,
      connections,
    })
  );
};

Our forest collections are also in forest folder:

// Content of forest/Baskets.js
const { collection } = require('forest-express-sequelize');

// This file allows you to add to your Forest UI:
// - Smart actions: https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions
// - Smart fields: https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields
// - Smart relationships: https://docs.forestadmin.com/documentation/reference-guide/relationships/create-a-smart-relationship
// - Smart segments: https://docs.forestadmin.com/documentation/reference-guide/segments/smart-segments
collection('Baskets', {
  actions: [],
  fields: [],
  segments: [],
});

Hello @Alejandro_Salazar,

Since the last message, I can see that you managed to update the schema that has been sent to Forest Admin with 2 changes:

  1. First, add a relationship
  2. Second, remove the relationship and remove the field accessDeviceId

I guess that you managed to fix you issue? Can you share how?

Hey!

Not really. That was me modifying the schema manually to check if the issue was related with “sending” the schema or with generating the schema.

At the end, the issue seems to be that my forest-schema file doesn’t get generated when making a change. We are currently 3 devs with the same issue

I checked the code, and NODE_ENV needs to be either dev or development for the schema to be updated automatically.

For information, as this problem has been experienced by multiple users of forest-express-based libraries, I created a PR to add warnings in the console when the schema is not updated because of the configuration.

This will be released on the last major version of forest-express-sequelize and forest-express-mongoose.

We are currently pushing for the usage of @forestadmin/agent to replace packages based on forest-express. In addition to providing a more explicit API for customizations, this package generates the schema and sends it to our servers, except if an explicit configuration property says the contrary.

1 Like

that seems to fix the issue, thanks a lot!

And great idea adding warnings in console :slight_smile:

2 Likes