{"record":{"id":"632ced507ac795ee","repo":"toeverything/AFFiNE","slug":"table-table-name-field-key-type-mismat","errorCode":null,"errorMessage":"[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.","messagePattern":"\\[Table\\((.+?)\\)\\]: Field '(.+?)' type mismatch\\. Expected (.+?) got (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/infra/src/orm/core/validators/data.ts","lineNumber":81,"sourceCode":"          if (val === null) {\n            if (!field.optional) {\n              throw new Error(\n                `[Table(${table.name})]: Field '${key}' is required but not set.`\n              );\n            }\n            continue;\n          }\n\n          const typeGet = inputType(val);\n\n          if (field.type === 'enum') {\n            if (!field.values?.includes(val)) {\n              throw new Error(\n                `[Table(${table.name})]: Field '${key}' value '${val}' is not valid. Expected one of [${field.values?.join(', ')}].`\n              );\n            }\n          } else if (!typeMatches(field.type, typeGet)) {\n            throw new Error(\n              `[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.`\n            );\n          }\n        } else if (!table.isDocumentTable) {\n          // strict check field existence for normal table\n          throw new Error(\n            `[Table(${table.name})]: Field '${key}' is not defined but set in entity.`\n          );\n        }\n      }\n    },\n  },\n  DataTypeShouldExactlyMatch: {\n    validate(table, data) {\n      const keys: Set<string> = new Set();\n\n      for (const key in data) {\n        const field = table.schema[key];","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/infra/src/orm/core/validators/data.ts#L63-L99","documentation":"A DataTypeShouldMatch validator case for non-enum fields: the runtime-observed input type of the value (computed by inputType) does not equal the schema-declared field.type. It fires on insert/update when, e.g., a string is supplied for a number field; the faulting input is data[key] whose dynamic type mismatches the schema for the named table.","triggerScenarios":"Thrown at packages/common/infra/src/orm/core/validators/data.ts:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the value to the field's declared type before saving.","Fix the schema type declaration if it does not match the data actually stored.","Check for serialization issues, e.g. numbers arriving as strings."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}