Cannot read properties of undefined (reading 'name')

I have a schema: roles,
export const roles = pgTable('roles', {
id: uuid('id').defaultRandom().notNull().primaryKey(),
precedence: integer('precedence').notNull().default(1),
name: text('name').notNull().unique(),
notification: notificationEnum('notification').notNull().default('none'),
notificationScope: notificationScopeEnum('notificationScope').notNull().default('self'),
invite: inviteEnum('invite').notNull().default('none'),
role: roleEnum('role').notNull().default('none'),
quickLink: quickLinkEnum('quickLink').notNull().default('none'),
course: courseEnum('course').notNull().default('none'),
profile: profile('profile').notNull().default('write'),
profileScope: profileScope('profileScope').notNull().default('self'),
batch: batch('batch').notNull().default('none'),
marks: marksEnum('marks_enum').notNull().default('read'),
marksScope: marksScope('marksScope').notNull().default('self'),
registrations: registrationEnum('registrations_enum').notNull().default('read'),
registrationScope: registrationScope('registrationScope').notNull().default('self')
})
export const roles = pgTable('roles', {
id: uuid('id').defaultRandom().notNull().primaryKey(),
precedence: integer('precedence').notNull().default(1),
name: text('name').notNull().unique(),
notification: notificationEnum('notification').notNull().default('none'),
notificationScope: notificationScopeEnum('notificationScope').notNull().default('self'),
invite: inviteEnum('invite').notNull().default('none'),
role: roleEnum('role').notNull().default('none'),
quickLink: quickLinkEnum('quickLink').notNull().default('none'),
course: courseEnum('course').notNull().default('none'),
profile: profile('profile').notNull().default('write'),
profileScope: profileScope('profileScope').notNull().default('self'),
batch: batch('batch').notNull().default('none'),
marks: marksEnum('marks_enum').notNull().default('read'),
marksScope: marksScope('marksScope').notNull().default('self'),
registrations: registrationEnum('registrations_enum').notNull().default('read'),
registrationScope: registrationScope('registrationScope').notNull().default('self')
})
I wrote code to update roles:
const updatedRole = await db
.update(roles)
.set(role)
.where(eq(roles.id, role.id as string))
.returning()

console.log('updatedRole:', updatedRole[0])
const updatedRole = await db
.update(roles)
.set(role)
.where(eq(roles.id, role.id as string))
.returning()

console.log('updatedRole:', updatedRole[0])
When i try updating a role i get the following error:
TypeError: Cannot read properties of undefined (reading 'name')
at -------\node_modules\drizzle-orm\index-1899b9ae.cjs:2084:51
at Array.flatMap (<anonymous>)
at PgDialect.buildUpdateSet (------\node_modules\drizzle-orm\index-1899b9ae.cjs:2082:14)
...
TypeError: Cannot read properties of undefined (reading 'name')
at -------\node_modules\drizzle-orm\index-1899b9ae.cjs:2084:51
at Array.flatMap (<anonymous>)
at PgDialect.buildUpdateSet (------\node_modules\drizzle-orm\index-1899b9ae.cjs:2082:14)
...
I opened up the file and noticed that 'buildUpdateSet' is unable to get one of the columns The file is from drizzle-orm so i might be a bug?
2 Replies
Angelelz
Angelelz12mo ago
It's unlikely bug, this is tested well Can you put together e reproduction repo? I can take a look Can you console log the role object, before calling db.update. I'm sure it has other keys that are not in the table
FractalFist
FractalFistOP12mo ago
yep, it was this. Thanks for taking the time to respond!
Want results from more Discord servers?
Add your server