Browsing a particular table throws "TypeError: Cannot read property 'startsWith' of undefined"

This is a template you can use to report issues. You can also drag images, videos and include Preformatted text

Expected behavior

I should be able to see the table data instead of “Your server encountered an error”

Actual behavior

I see “Your server encountered an error”

Failure Logs

TypeError: Cannot read property 'startsWith' of undefined
    at /xxx/node_modules/forest-express-sequelize/dist/services/query-builder.js:92:21
    at Array.filter (<anonymous>)
    at /xxx/node_modules/forest-express-sequelize/dist/services/query-builder.js:91:62
    at Array.forEach (<anonymous>)
    at QueryBuilder.getIncludes (/xxx/node_modules/forest-express-sequelize/dist/services/query-builder.js:86:8)
    at ResourcesGetter.count (/xxx/node_modules/forest-express-sequelize/dist/services/resources-getter.js:213:39)

Doing some digging of my own it seems an undefined snuck into the fieldNamesRequested array in this.getIncludes:
[ undefined, 'isOwner', '', '' ]


Please provide any relevant information about your setup.

  • Package Version: 4.1.7 (lumber)
  • Express Version: ~4.17.1
  • Sequelize Version: ~5.15.1
  • Database Dialect: Postgres
  • Database Version: 12.6
  • Project Name: saas-ludbac

Here’s the table I’m trying to view:

create table app_public.team_memberships (
  team_id uuid references app_public.teams on delete cascade,
  user_id uuid references app_public.users on delete cascade,
  is_owner boolean not null default false,
  unique (team_id, user_id)

Referenced tables:

create table app_public.teams (
  id uuid primary key default gen_random_uuid(),
  name citext not null

create table app_public.users (
  id uuid primary key default gen_random_uuid(),
  full_name text not null,
  email citext unique not null check (email ~ '[^@]+@[^@]+\.[^@]+'),
  is_verified boolean not null default false

It also seems like app_public.team_memberships is not automatically recognized as a junction table as there is no belongsToMany in models.users.


Hi @ludwig,

What is your forest-express-sequelize version please?


The forest-express-sequelize version is 7.6.3

You’re right.
Does the problem appear on every collection or just one?

I only have four tables I’m trying Forest Admin on but all of them work except this one.

Hi @ludwig,

I confirm I have exactly the same error as you with the schema you provided.
Bug reproduced, half resolved. The investigation is not done yet, I will inform you later.

Thank you for giving so precise information.

1 Like

Hi @ludwig,

This is issue is due to the fact that the Forest Admin agent does not handle well tables that have no primary keys defined on a table. If you had defined a composite primary key on this table it would display well.

create table "teamMemberships" (
  "teamId" integer references teams on delete cascade,
  "userId" integer references users on delete cascade,
  "isOwner" boolean not null default false,
  unique ("teamId", "userId")

-- versus

create table "teamMemberships" (
  "teamId" integer references teams on delete cascade,
  "userId" integer references users on delete cascade,
  "isOwner" boolean not null default false,
  primary key ("teamId", "userId")

We’ll try to find a patch to support join tables without primary keys.

Unfortunately, even if we manage to be defensive against this specific first error.
Forest Admin won’t be able to display the records of tables that does not have any primary key.
This is due to technical “store” reasons on the web client.

Let me create a feature request to discuss how we could prioritise such use case support.

Oh! Well it seems I just mistakenly put a unique instead of a primary key there so don’t feel like you have to support some super special use case if it’s not something you’ve encountered before. Thanks for the timely help!

1 Like