prisma: MySQL Data Truncated error when using non-ascii characters
Bug description
PrismaClientKnownRequestError:
Invalid `prisma.carrier.upsert()` invocation in
C:\Users\akxe\Documents\programming\rita\apps\server\src\cron\rs-foto-import\handle-created.ts:114:34
111
112 const { photos, mapImage, carrierID, ...update } = data;
113
→ 114 const promise = prisma.carrier.upsert(
Unique constraint failed on the constraint: `PRIMARY`
at Cn.handleRequestError (C:\Users\akxe\Documents\programming\rita\node_modules\@prisma\client\runtime\library.js:123:6817)
at Cn.handleAndLogRequestError (C:\Users\akxe\Documents\programming\rita\node_modules\@prisma\client\runtime\library.js:123:6206)
at Cn.request (C:\Users\akxe\Documents\programming\rita\node_modules\@prisma\client\runtime\library.js:123:5926)
at l (C:\Users\akxe\Documents\programming\rita\node_modules\@prisma\client\runtime\library.js:128:9968)
But the weird thing is, that I get this error above:
C:\Users\akxe\Documents\programming\rita\node_modules\@prisma\client\runtime\library.js:123
`)}var Ji=({clientMethod:e,activeProvider:t,activeProviderFlavour:r})=>n=>{r!==void 0&&(t=r);let i="",o;if(Array.isArray(n)){let[s,...a]=n;i=s,o={values:gr(a||[]),__prismaRawParameters__:!0}}else switch(t){case"sqlite":case"mysql":{i=n.sql,o={values:gr(n.values),__prismaRawParameters__:!0};break}case"cockroachdb":case"postgresql":case"postgres":{i=n.text,o={values:gr(n.values),__prismaRawParameters__:!0};break}case"sqlserver":{i=il(n),o={values:gr(n.values),__prismaRawParameters__:!0};break}default:throw new Error(`The ${t} provider does not support ${e}`)}return o?.values?ll(`prisma.${e}(${i}, ${o.values})`):ll(`prisma.${e}(${i})`),{query:i,parameters:o}},ul={requestArgsToMiddlewareArgs(e){return[e.strings,...e.values]},middlewareArgsToRequestArgs(e){let[t,...r]=e;return new oe(t,r)}},cl={requestArgsToMiddlewareArgs(e){return[e]},middlewareArgsToRequestArgs(e){return e[0]}};function Hi(e){return function(r){let n,i=(o=e)=>{try{return o===void 0||o?.kind==="itx"?n??(n=pl(r(o))):pl(r(o))}catch(s){return Promise.reject(s)}};return{then(o,s){return i().then(o,s)},catch(o){return i().catch(o)},finally(o){return i().finally(o)},requestTransaction(o){let s=i(o);return s.requestTransaction?s.requestTransaction(o):s},[Symbol.toStringTag]:"PrismaPromise"}}}function pl(e){return typeof e.then=="function"?e:Promise.resolve(e)}var dl={isEnabled(){return!1},getTraceParent(){return"00-10-10-00"},async createEngineSpan(){},getActiveContext(){},runInChildSpan(e,t){return t()}},Wi=class{isEnabled(){return this.getGlobalTracingHelper().isEnabled()}getTraceParent(t){return this.getGlobalTracingHelper().getTraceParent(t)}createEngineSpan(t){return this.getGlobalTracingHelper().createEngineSpan(t)}getActiveContext(){return this.getGlobalTracingHelper().getActiveContext()}runInChildSpan(t,r){return this.getGlobalTracingHelper().runInChildSpan(t,r)}getGlobalTracingHelper(){return globalThis.PRISMA_INSTRUMENTATION?.helper??dl}};function ml(e){return e.includes("tracing")?new Wi:dl}function fl(e,t=()=>{}){let r,n=new Promise(i=>r=i);return{then(i){return--e===0&&r(t()),i?.(n)}}}var Kd=["$connect","$disconnect","$on","$transaction","$use","$extends"],zi=Kd;function gl(e){return typeof e=="string"?e:e.reduce((t,r)=>{let n=typeof r=="string"?r:r.level;return n==="query"?t:t&&(r==="info"||t==="info")?"info":n},void 0)}var wn=class{constructor(){this._middlewares=[]}use(t){this._middlewares.push(t)}get(t){return this._middlewares[t]}has(t){return!!this._middlewares[t]}length(){return this._middlewares.length}};var hl=S(li());function Pn(e){return typeof e.batchRequestIdx=="number"}function vn(e){return e===null?e:Array.isArray(e)?e.map(vn):typeof e=="object"?Qd(e)?Gd(e):pt(e,vn):e}function Qd(e){return e!==null&&typeof e=="object"&&typeof e.$type=="string"}function Gd({$type:e,value:t}){switch(e){case"BigInt":return BigInt(t);case"Bytes":return Buffer.from(t,"base64");case"DateTime":return new Date(t);case"Decimal":return new Pe(t);case"Json":return JSON.parse(t);default:He(t,"Unknown tagged value")}}function yl(e){if(e.action!=="findUnique"&&e.action!=="findUniqueOrThrow")return;let t=[];return e.modelName&&t.push(e.modelName),e.query.arguments&&t.push(Yi(e.query.arguments)),t.push(Yi(e.query.selection)),t.join("")}function Yi(e){return`(${Object.keys(e).sort().map(r=>{let n=e[r];return typeof n=="object"&&n!==null?`(${r} ${Yi(n)})`:r}).join(" ")})`}var Jd={aggregate:!1,aggregateRaw:!1,createMany:!0,createOne:!0,deleteMany:!0,deleteOne:!0,executeRaw:!0,findFirst:!1,findFirstOrThrow:!1,findMany:!1,findRaw:!1,findUnique:!1,findUniqueOrThrow:!1,groupBy:!1,queryRaw:!1,runCommandRaw:!0,updateMany:!0,updateOne:!0,upsertOne:!0};function Zi(e){return Jd[e]}var Tn=class{constructor(t){this.options=t;this.tickActive=!1;this.batches={}}request(t){let r=this.options.batchBy(t);return r?(this.batches[r]||(this.batches[r]=[],this.tickActive||(this.tickActive=!0,process.nextTick(()=>{this.dispatchBatches(),this.tickActive=!1}))),new Promise((n,i)=>{this.batches[r].push({request:t,resolve:n,reject:i})})):this.options.singleLoader(t)}dispatchBatches(){for(let t in this.batches){let r=this.batches[t];delete this.batches[t],r.length===1?this.options.singleLoader(r[0].request).then(n=>{n instanceof Error?r[0].reject(n):r[0].resolve(n)}).catch(n=>{r[0].reject(n)}):(r.sort((n,i)=>this.options.batchOrder(n.request,i.request)),this.options.batchLoader(r.map(n=>n.request)).then(n=>{if(n instanceof Error)for(let i=0;i<r.length;i++)r[i].reject(n);else for(let i=0;i<r.length;i++){let o=n[i];o instanceof Error?r[i].reject(o):r[i].resolve(o)}}).catch(n=>{for(let i=0;i<r.length;i++)r[i].reject(n)}))}}get[Symbol.toStringTag](){return"DataLoader"}};var Hd=O("prisma:client:request_handler"),Cn=class{constructor(t,r){this.logEmitter=r,this.client=t,this.dataloader=new Tn({batchLoader:ca(async({requests:n,customDataProxyFetch:i})=>{let{transaction:o,otelParentCtx:s}=n[0],a=n.map(p=>p.protocolQuery),l=this.client._tracingHelper.getTraceParent(s),u=n.some(p=>Zi(p.protocolQuery.action));return(await this.client._engine.requestBatch(a,{traceparent:l,transaction:Wd(o),containsWrite:u,customDataProxyFetch:i})).map((p,d)=>{if(p instanceof Error)return p;try{return this.mapQueryEngineResult(n[d],p)}catch(f){return f}})}),singleLoader:async n=>{let i=n.transaction?.kind==="itx"?xl(n.transaction):void 0,o=await this.client._engine.request(n.protocolQuery,{traceparent:this.client._tracingHelper.getTraceParent(),interactiveTransaction:i,isWrite:Zi(n.protocolQuery.action),customDataProxyFetch:n.customDataProxyFetch});return this.mapQueryEngineResult(n,o)},batchBy:n=>n.transaction?.id?`transaction-${n.transaction.id}`:yl(n.protocolQuery),batchOrder(n,i){return n.transaction?.kind==="batch"&&i.transaction?.kind==="batch"?n.transaction.index-i.transaction.index:0}})}async request(t){try{return await this.dataloader.request(t)}catch(r){let{clientMethod:n,callsite:i,transaction:o,args:s}=t;this.handleAndLogRequestError({error:r,clientMethod:n,callsite:i,transaction:o,args:s})}}mapQueryEngineResult({dataPath:t,unpacker:r},n){let i=n?.data,o=n?.elapsed,s=this.unpack(i,t,r);return process.env.PRISMA_CLIENT_GET_TIME?{data:s,elapsed:o}:s}handleAndLogRequestError(t){try{this.handleRequestError(t)}catch(r){throw this.logEmitter&&this.logEmitter.emit("error",{message:r.message,target:t.clientMethod,timestamp:new Date}),r}}handleRequestError({error:t,clientMethod:r,callsite:n,transaction:i,args:o}){if(Hd(t),zd(t,i)||t instanceof Me)throw t;if(t instanceof U&&Yd(t)){let a=bl(t.meta);En({args:o,errors:[a],callsite:n,errorFormat:this.client._errorFormat,originalMethod:r,clientVersion:this.client._clientVersion})}let s=t.message;throw n&&(s=Pt({callsite:n,originalMethod:r,isPanic:t.isPanic,showColors:this.client._errorFormat==="pretty",message:s})),s=this.sanitizeMessage(s),t.code?new U(s,{code:t.code,clientVersion:this.client._clientVersion,meta:t.meta,batchRequestIdx:t.batchRequestIdx}):t.isPanic?new ue(s,this.client._clientVersion):t instanceof K?new K(s,{clientVersion:this.client._clientVersion,batchRequestIdx:t.batchRequestIdx}):t instanceof F?new F(s,this.client._clientVersion):t instanceof ue?new ue(s,this.client._clientVersion):(t.clientVersion=this.client._clientVersion,t)}sanitizeMessage(t){return this.client._errorFormat&&this.client._errorFormat!=="pretty"?(0,hl.default)(t):t}unpack(t,r,n){if(!t||(t.data&&(t=t.data),!t))return t;let i=Object.values(t)[0],o=r.filter(a=>a!=="select"&&a!=="include"),s=vn(Ai(i,o));return n?n(s):s}get[Symbol.toStringTag](){return"RequestHandler"}};function Wd(e){if(e){if(e.kind==="batch")return{kind:"batch",options:{isolationLevel:e.isolationLevel}};if(e.kind==="itx")return{kind:"itx",options:xl(e)};He(e,"Unknown transaction kind")}}function xl(e){return{id:e.id,payload:e.payload}}function zd(e,t){return Pn(e)&&t?.kind==="batch"&&e.batchRequestIdx!==t.index}function Yd(e){return e.code==="P2009"||e.code==="P2012"}function bl(e){if(e.kind==="Union")return{kind:"Union",errors:e.errors.map(bl)};if(Array.isArray(e.selectionPath)){let[,...t]=e.selectionPath;return{...e,selectionPath:t}}return e}var El="5.5.2";var wl=El;function Pl(e){return e.map(t=>{let r={};for(let n of Object.keys(t))r[n]=vl(t[n]);return r})}function vl({prisma__type:e,prisma__value:t}){switch(e){case"bigint":return BigInt(t);case"bytes":return Buffer.from(t,"base64");case"decimal":return new Pe(t);case"datetime":case"date":return new Date(t);case"time":return new Date(`1970-01-01T${t}Z`);case"array":return t.map(vl);default:return t}}var Ml=S(Ui());var q=class extends Error{constructor(t){super(t+`
There is also a lot and lot of spaces and a ^ symbol at the end pointing to nowhere…
How to reproduce
- Insert into table
Ba value:{ aID: 1, order: 1, value: 1 } - Upsert into table
A:{ aID: 1, B: { create: { aID: 1, order: 1, value: 1 } } }whereaID: 1 - Observe error
Expected behavior
The error should say that it failed because of the nested insert.
Prisma information
model A {
aID Int @id
B B[]
}
model B {
aID Int
order Int
value String
A A
@@id([aID, order])
}
Environment & setup
- OS: Windows
- Database: MySQL
- Node.js version: v20.9.0
Prisma Version
Environment variables loaded from .env
prisma : 5.5.2
@prisma/client : 5.5.2
Current platform : windows
Query Engine (Node-API) : libquery-engine aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Schema Engine : schema-engine-cli aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a (at node_modules\@prisma\engines\schema-engine-windows.exe)
Schema Wasm : @prisma/prisma-schema-wasm 5.5.1-1.aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a
Default Engines Hash : aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a
Studio : 0.494.0
Preview Features : tracing
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 18 (18 by maintainers)
@Druue for me it works (The SQL is created correctly). Maybe… Could it be OS? I use windows (in dev)
@Druue thanks for the effort. What version of MySQL are you using?
Edit: Just got around to testing it again, and for me, the script easily created 2 rows in the table
company.I use MySQL version 8.0.35
@millsp Here is repo https://github.com/Akxe/prisma-debug
All you need to do is to run
npm run start(afternpm i)