Cannot create row from Forest Admin because identifier cannot be null

Description

I just connected my database to forest admin and everything is displayed properly. When I try to create a row in a table from Forest form, I get an error saying that the id cannot be null.
In SQL it’s set to GENERATED ALWAYS AS IDENTITY and is PRIMARY KEY. Inserting manually works well in SQL.

Expected behavior

When using the Forest form to create a row, the id should be read-only and be let blank and created automatically when inserting. No error displayed when creating in Forest app without explicitly setting the id.

Actual behavior

When creating a row without setting the id, I get a 422 error notNull Violation: agent.agentId cannot be null, because the id is not set from the UI. I can then not create a row.

Context

  • Package Version:
  • Express Version: 4.17.1
  • Sequelize Version: 5.15.1
  • Database Dialect: Postgres
  • Database Version:
  • Project Name: forest_admin_edumiam

Model from the agent table

agentId: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      allowNull: false,
    },

Hello @alexphiev ! :wave: Welcome to our community :tada: :confetti_ball:

Can you share your forest-express-seqeulize Package Version ? A colleague will take the relay on this subject.

Thanks in advance. Have a nice day.
Morgan.

Hi @morganperre ,

Actually the above packages are slightly wrong:
express@4.17.1
forest-express-sequelize@8.3.2
sequelize@5.15.2

Hello @alexphiev,

Could you please share with us the SQL schema of your agent table? It will help me reproduce your issue.

If I remember correctly, the ForestAdmin frontend will set the field as read-only if your JS model definition specifies a default value for your agentId field.

Thanks

Hi @anon79585656

Here is the SQL schema:

CREATE TABLE IF NOT EXISTS agent
(
    agent_id     INT GENERATED ALWAYS AS IDENTITY,
    email        TEXT UNIQUE NOT NULL,
    first_name   TEXT        NOT NULL,
    last_name    TEXT        NOT NULL,
    created_date timestamptz NOT NULL DEFAULT now(),
    PRIMARY KEY (agent_id)
);

I thought the GENERATED ALWAYS AS IDENTITY is by itself setting a default value. Maybe your code handles the id definition of type SERIAL UNIQUE only?

Thank you

@alexphiev,

Sorry it took some time to reproduce and investigate on my end.

We indeed seem to have a bug on our side with the GENERATED ALWAYS AS IDENTITY definition.

For now, the two workarounds I can offer would be

  1. rename agent_id as id
  2. use SERIAL as the type for agent_id

This is not ideal as it requires changes on your database schema.

I’ll continue investigating and share this with our team.