I'm using Prisma upsert and getting an error about missing a required value when I'm trying to set one of the fields, which is an array type, specifically numeric[]
.
I'm using Prisma version 2.6.0
Data is getting into the database for all except a handful of rows and I'm getting an error thrown by Prisma on those rows when the upsert executes.
The error I'm getting from prisma is related to the array I'm trying to set:
PrismaClientKnownRequestError:
Invalid `prisma.node.upsert()` invocation in
/usr/development/project/dist/project-tsdx.cjs.development.js:604:46
Missing a required value at `Mutation.upsertOnenode.create.nodeCreateInput.temperature.nodeCreatetemperatureInput.set`
at PrismaClientFetcher.request (/usr/development/project/node_modules/@prisma/client/runtime/index.js:1:227598)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 3366) {
code: 'P2012',
meta: {
path: 'Mutation.upsertOnenode.create.nodeCreateInput.temperature.nodeCreatetemperatureInput.set'
}
}
The object that the exception occurs on has the following values:
threw this node:
Node {
name: 'ahostname',
state: 'NONE',
cores: -1,
busycpus: 0,
queue: 'NONE',
rack: 'NONE',
jobs: '',
temperature: [ -1 ],
tempupdatetime: '1970-01-01T00:00:00.000Z',
power: 0,
powerupdatetime: '1970-01-01T00:00:00.000Z',
uptime: 20,
loadavg1: 0,
loadavg5: 0.01,
loadavg15: 0.05,
cpuusage: 0.2,
updatetime: '2020-09-01T17:29:02.000Z'
}
My schema for the Node model is as follows:
model node {
node String @id
state String
cores Int
busycpus Int
queue String
rack String
jobs String
temperature Float[]
tempupdatetime DateTime
power Float
powerupdatetime DateTime
uptime Int
loadavg1 Float
loadavg5 Float
loadavg15 Float
cpuusage Float
updatetime DateTime
}
Finally, the actual code that I'm using to set this array is below:
import { PrismaClient } from '@prisma/client'
import { NodeStats } from '../sources/nodeStats'
const prisma = new PrismaClient()
export default async (nodes: NodeStats) => {
const { timestamp, ...others } = nodes
//@ts-ignore
let currentNode
const promises = Object.keys(others).map(async nodeName => {
try {
const node = nodes[nodeName]
currentNode = node
let { temperature, name, ...others } = node
if (temperature.length === 1 && temperature[0] === 0){
node.temperature = [-1]
temperature = [-1]
}
// if(!temperature) console.log(currentNode)
await prisma.node.upsert({
create: { ...others, node: name, temperature: {set: [...temperature]}},
where: { node: nodeName },
update: { ...others, node: name, temperature: { set: [...temperature] } },
})
} catch (e) {
console.error("threw this node:", currentNode)
console.error(e)
}
})
return Promise.all(promises)
}
All of the Node
s that get thrown have one thing in common, their temperature
value is [0]
. I tried to change it to [-1]
but that didn't stop the error from occurring. Really puzzled on what is going on here, any tips would be appreciated.