Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: drizzle-zod's createInsertSchema() can't handle column of type vector #2424

Open
sp88011 opened this issue Jun 2, 2024 · 15 comments · May be fixed by #2780
Open

[BUG]: drizzle-zod's createInsertSchema() can't handle column of type vector #2424

sp88011 opened this issue Jun 2, 2024 · 15 comments · May be fixed by #2780
Labels
bug Something isn't working db/postgres drizzle/zod

Comments

@sp88011
Copy link

sp88011 commented Jun 2, 2024

What version of drizzle-orm are you using?

0.31.0

What version of drizzle-kit are you using?

0.22.1

Describe the Bug

One of my columns is of type vector (from the pgvector extension). I use createInsertSchema() from the drizzle-zod package to create a Zod schema for that table. When navigating to the page where that Zod schema is used, I'm getting the following error:

Error Cannot use 'in' operator to search for 'enumValues' in undefined

When I remove the vector column, everything works fine. I'm not really sure why the error talks about enumValues at all..but I figured it must have something to do with the vector column.

export const productSchema = createInsertSchema(T_product);
...

schema:

export const T_product = pgTable(
  "product",
  {
    id: varchar("id", { length: 36 })
      .$defaultFn(() => uuidv7())
      .primaryKey(),
    createdAt: timestamp("createdAt").defaultNow(),
    updatedAt: timestamp("updatedAt"),
    name: text("name").notNull(),
    embedding: vector("embedding", { dimensions: 384 }),
//...
  },
  (t) => ({
    embeddingIdx: index("embedding_idx").using(
      "hnsw",
      t.embedding.op("vector_cosine_ops"),
    ),
  }),
);

Expected behavior

Error should not happen.

Environment & setup

I'm using "drizzle-zod": "^0.5.1"

Full Error stack:

⨯ TypeError: Cannot use 'in' operator to search for 'enumValues' in undefined
    at eval (webpack-internal:///(rsc)/./node_modules/drizzle-zod/index.mjs:17:1262)
    at p (webpack-internal:///(rsc)/./node_modules/drizzle-zod/index.mjs:17:1319)
    at p (webpack-internal:///(rsc)/./node_modules/drizzle-zod/index.mjs:17:1789)
    at eval (webpack-internal:///(rsc)/./node_modules/drizzle-zod/index.mjs:17:564)
    at Array.map (<anonymous>)
    at c (webpack-internal:///(rsc)/./node_modules/drizzle-zod/index.mjs:17:547)
    at eval (webpack-internal:///(rsc)/./utils/zodSchemas.ts:65:88)
    at (rsc)/./utils/zodSchemas.ts (/Users/j/Documents/webdev/market-analytics/.next/server/app/admin/entities/page.js:1944:1)
    at __webpack_require__ (/Users/j/Documents/webdev/market-analytics/.next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./app/admin/entities/validations.ts:15:75)
    at (rsc)/./app/admin/entities/validations.ts (/Users/j/Documents/webdev/market-analytics/.next/server/app/admin/entities/page.js:1370:1)
    at __webpack_require__ (/Users/j/Documents/webdev/market-analytics/.next/server/webpack-runtime.js:33:43)
    at eval (webpack-internal:///(rsc)/./app/admin/entities/page.tsx:7:70)
    at (rsc)/./app/admin/entities/page.tsx (/Users/j/Documents/webdev/market-analytics/.next/server/app/admin/entities/page.js:1359:1)
    at Function.__webpack_require__ (/Users/j/Documents/webdev/market-analytics/.next/server/webpack-runtime.js:33:43)
    at async e9 (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:396554)
    at async tb (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:400212)
    at async tS (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:400773)
    at async tS (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:400904)
    at async tS (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:400904)
    at async tS (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:400904)
    at async tR (/Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:36:2130)
    at async /Users/j/Documents/webdev/market-analytics/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:36:2722 {
  digest: '3542844501',
  page: '/admin/products'
}```
@sp88011 sp88011 added the bug Something isn't working label Jun 2, 2024
@matthiasbayer
Copy link

Experiencing the same error after updating to latest drizzle-orm 0.31.0.

The problems seems to be that the vector column is defined as type: array but doesn't expose a baseColumn value that is used by drizzle-zod here

@jgontrum
Copy link

jgontrum commented Jun 6, 2024

Same here. Followed this official guide (https://orm.drizzle.team/learn/guides/vector-similarity-search) and using vector breaks my code when I'm using createInsertSchema on that table.

@feliche93
Copy link

Can also confirm that I have the same issue 🤔 is there any quick fix around this except remove the column?

@nicoalbanese
Copy link

I experienced as well. As a temporary solution, I defined the zod schema manually for just my embedding table.

I have the content in one table, then when a new row gets added, it is broken into chunks and each chunk is saved in another table (embeddings) that has a FK to the id of the content.

@mattiasbonte
Copy link

FYI for those who are blocked because of this, I was able to avoid this issue by creating a new embeddings table and joining them onto my profiles. Which is probably a better way for our project in the long run.

@waltershewmake
Copy link

I think this may be happening with the point column type as well in postgres

@diego-escobedo
Copy link
Contributor

Facing the same issue with both selectSchema and insertSchema with vector types specifically.

@yantakus
Copy link

I can confirm the same problem with point type. Is there any workaround? Or maybe a fix, which is better?

Sukairo-02 added a commit to Sukairo-02/drizzle-orm that referenced this issue Jul 3, 2024
@dpromisel
Copy link

Also facing this issue with vector columns when using createSelectSchema and createInsertSchema

@ludersGabriel
Copy link

I can also confirm that it is still happening with point type from drizzle's pg-core

@danielivanovz
Copy link

This is still happening for Point type

"drizzle-orm": "^0.32.0"
"drizzle-zod": "^0.5.1"

@austinm911
Copy link

for now you can't co-locate the zod schemas in any files that export schemas. you will have to have the schemas in a separate file for now

@timur-khakhalev
Copy link

timur-khakhalev commented Sep 26, 2024

hi! any updates here? its still happen on
"drizzle-kit": "^0.24.2",
"drizzle-orm": "^0.33.0",
"drizzle-zod": "^0.5.1",

@Matangub
Copy link

Matangub commented Oct 3, 2024

I can confirm it happens for me as well on the latest drizzle zod version

@Brenndoerfer
Copy link

Downgrading to drizzle-zod@0.4.4 resolved it for me in the interim

npm i drizzle-zod@0.4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/postgres drizzle/zod
Projects
None yet
Development

Successfully merging a pull request may close this issue.