Skip to content

DATEONLY field in composite primary key causes detail page error due to inconsistent date format #1441

@mash

Description

@mash

Expected behavior

When clicking a record with a composite primary key that includes a DATEONLY field, the detail page should load correctly.

Actual behavior

The API response includes the timestamp in the composite primary key ID:

{
  "id": "1|group-123|2025-01-15T00:00:00.000Z"
}

When clicking the record, Forest Admin uses this ID to construct the detail page URL, but the lookup fails because the date format is inconsistent.

Expected ID format:

1|group-123|2025-01-15

Actual ID format:

1|group-123|2025-01-15T00:00:00.000Z

Context

  • Package Version: @forestadmin/agent@1.71.2, @forestadmin/datasource-sequelize@1.13.1
  • Database: MySQL
  • ORM: Sequelize
  • Field type: DataTypes.DATEONLY as part of composite primary key

Workaround

Adding a getter to normalize the date format in the Sequelize model:

day: {
  type: DataTypes.DATEONLY,
  primaryKey: true,
  allowNull: false,
  get() {
    const value = this.getDataValue('day');
    if (value instanceof Date) {
      return value.toISOString().slice(0, 10);
    }
    if (typeof value === 'string' && value.includes('T')) {
      return value.slice(0, 10);
    }
    return value;
  },
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions