#schema error

1 messages · Page 1 of 1 (latest)

hearty swiftBOT
#

Hi @tawdry furnace. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I can see you're encountering a schema validation error in your Convex application. Let me explain what's happening.

The Error

The error occurs because the value you're trying to store in the resultIds field doesn't match the validator defined in your schema. Specifically:

Failed to insert or update a document in table "tasks" because it does not match the schema: Value does not match validator.
Path: .resultIds
Value: {0: "ks74yxajz2p02fs3j9w76ezhz57fdvz7"}
Validator: v.array(v.id("workspaceImages"))

The Issue

Looking at your code and the error message, I can identify the problem:

  1. Your validator expects resultIds to be an array of IDs from the "workspaceImages" table: v.array(v.id("workspaceImages"))

  2. However, the value being passed is an object with numeric keys instead of an array: {0: "ks74yxajz2p02fs3j9w76ezhz57fdvz7"}

  3. Your code shows that results is correctly an array: [ 'ks74yxajz2p02fs3j9w76ezhz57fdvz7' ]

  4. The issue likely occurs when you call prismaToConvex(params), which might be transforming your array into an object.

Solution

There are a few ways to fix this:

  1. Remove the prismaToConvex transformation: If this function is converting your arrays to objects, you might need to modify it or bypass it for this field.

  2. Ensure proper array format: Make sure the value is a proper JavaScript array before saving:

    resultIds: Array.isArray(results) ? results : Object.values(results),
    
  3. Check your schema: Ensure your schema definition matches what you're trying to store. If you're consistently storing objects instead of arrays, you might need to adjust your schema validator.

#

Convex enforces schema validation at runtime to ensure data integrity Schema Validation. When you attempt to insert or update a document that doesn't match the schema, Convex will throw an error like the one you're seeing.

If you need to temporarily bypass schema validation while you fix your data model, you can set schemaValidation: false in your schema options Schema Options, but this is generally not recommended for production use.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: