8000 [Bug]: defineDatasource dimensions require id (docs mismatch) and schema push fails updating existing dimensions · Issue #936 · storyblok/monoblok · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: defineDatasource dimensions require id (docs mismatch) and schema push fails updating existing dimensions #936

Done

Description

@leifmarcus

Package

@storyblok/schema, storyblok (CLI)

Bug Description

There are two related problems with datasource dimensions in the schema workflow:

1. defineDatasource() typing doesn't match the docs.
The defineDatasource() docs show dimensions declared with only name and entry_value. The types, however, require id on every dimension, so the documented example doesn't compile.

Datasource reuses the generated CAPI response type, where Dimension.id: number is required. DATASOURCE_DEFAULTS only makes the top-level id, created_at, updated_at and dimensions optional, not the fields of each dimension.

The CLI already strips dimension ids before diffing (DATASOURCE_DIMENSION_STRIP_KEYS) and pushing (toDatasourceCreate only sends name and entry_value). Because of that, users have to enter a placeholder such as id: 0 just to satisfy TypeScript, and the CLI ignores it.

2. Updating a datasource that already has dimensions fails with dimensions.entry_value: has already been taken.
toDatasourceUpdate sends all local dimensions as dimensions_attributes entries with only { name, entry_value }. It doesn't attach the id of the matching remote dimension. With nested attributes, an entry without an id is treated as a new record, so dimensions that already exist get created again and the uniqueness check on entry_value fails.

Setting id in the schema doesn't help, because the CLI strips it (see above). Workarounds such as id: 0 therefore only fix the type error and don't affect the push.

This happens for any update to a datasource that already has dimensions. Examples are adding a new dimension, or renaming a dimension, which also ends up as destroy + create with the same entry_value because local and remote dimensions are matched on name::entry_value.

Steps to Reproduce

Typing

import { defineDatasource } from '@storyblok/schema';

// Example copied from the docs
export const colorsDatasource = defineDatasource({
  name: 'Colors',
  slug: 'colors',
  dimensions: [
    { name: 'Light Mode', entry_value: 'light' },
    { name: 'Dark Mode', entry_value: 'dark' },
  ],
});

tsc --noEmit --strict reports:

error TS2741: Property 'id' is missing in type '{ name: string; entry_value: string; }' but required in type 'Dimension'.

Push

  1. Define a datasource with dimensions (for example the one above, with id: 0 added to satisfy the types) and run storyblok schema push. The datasource is created.
  2. Add another dimension, e.g. { name: 'High Contrast', entry_value: 'contrast' }.
  3. Run storyblok schema push again. The datasource update fails.

Expected Behavior

  • The documented defineDatasource() example type-checks: dimension id (and datasource_id, created_at, updated_at) are optional in the input type, because they are assigned by the API and ignored by the CLI.
  • storyblok schema push updates a datasource that already has dimensions. Existing dimensions are matched to their remote counterparts (e.g. by entry_value) and sent with their remote id; only new dimensions are sent without an id.

Actual Behavior

  • The documented example fails to type-check unless a dummy id is added to each dimension.
  • Pushing an update to a datasource that already has dimensions fails with dimensions.entry_value: has already been taken.

Environment

@storyblok/schema: 0.7.0
storyblok (CLI): 4.26.1

The code referenced above is identical on main (89b9875).

Error Logs

Output of storyblok schema push (datasource name replaced; each error is repeated once per affected dimension):

▲ error Failed to update datasource <datasource>
▲ error dimensions.entry_value: has already been taken
▲ error dimensions.name: has already been taken
▲ error API Error: The request was well-formed but was unable to be followed due to semantic errors {
  name: 'API Error',
  message: 'Failed to update datasource <datasource>',
  httpCode: 422,
  cause: 'The request was well-formed but was unable to be followed due to semantic errors',
  errorId: 'unprocessable_entity',
  responseData: {
    'dimensions.entry_value': [ 'has already been taken', ... ],
    'dimensions.name': [ 'has already been taken', ... ]
  }
}

The error counts match the payload built by toDatasourceUpdate exactly:

Local dimension vs. remote Errors per dimension
Unchanged (same name and entry_value), sent without id entry_value + name taken
Renamed (same entry_value, new name), sent without id entry_value taken
New entry_value none

The renamed dimensions fail even though the old remote dimensions are sent with _destroy: true in the same request. The uniqueness validation still sees the existing rows, so destroy + re-create can't be used to rename a dimension.

Additional Context

Possible fixes:

  • Schema: override dimensions in the input type with a dedicated input shape, e.g. Array<Pick<Dimension, 'name' | 'entry_value'> & Partial<Dimension>>, so the docs example compiles.
  • CLI: in toDatasourceUpdate, resolve each local dimension against remote.dimensions (by entry_value) and include the remote id. That way existing dimensions are updated, including renames, instead of being created again. The same function is used by schema rollback, so rollback is likely affected too.

Activity

  1. added a commit that references this issue on Nov 16, 2026
    ef2273d
  2. added
    pkg: cli
    type: bug
    pkg: schema
    on Nov 17, 2026
  3. added 4 commits that reference this issue on Nov 19, 2026
    f94c480
    ad65d5f
    4fccbd3
    cffddd5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pkg: clipkg: schematype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0