Hey, Any idea why this is happening? “Attempted ...
# orm-help
j
Hey, Any idea why this is happening? “Attempted to serialize scalar ‘null’ with incompatible type ‘Decimal’ for field points.” In the ads table, there are no fields named as points.
Copy code
Error:  Invalid `prisma_1.default.ads.findMany()` invocation in /usr/src/app/dist/api/offerwall/getClickCampaigns.js:16:50

  Attempted to serialize scalar ‘null’ with incompatible type ‘Decimal’ for field points.
    at Object.request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:39813:15)
    at async PrismaClient._request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:40637:18)
    at async getClickCampaigns (/usr/src/app/dist/api/offerwall/getClickCampaigns.js:16:23)
i
1. what's the relevant schema model, and 2. what's the particular query you're making?
Generally it sounds like you've got a
null
in a field that prisma expects to be non-
null
perhaps doing
Decimal?
would fix your problem?
j
Schema, Query :
Copy code
model ads {
  id               String        @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  name             String
  url              String
  geo              String?
  geoExclude       Boolean       @default(false)
  image            String?
  user_id          String        @db.Uuid
  status           Boolean       @default(true)
  created_at       DateTime      @default(now()) @db.Timestamptz(6)
  updated_at       DateTime      @default(now()) @db.Timestamptz(6)
  description      String
  credits          Decimal       @default(0) @db.Decimal
  browsers         String?
  browsers_exclude Boolean       @default(false)
  featured         Boolean?      @default(false)
  featured_expire  DateTime?     @db.Date
  type             String?       @db.Uuid
  featured_spend   Decimal       @default(0) @db.Decimal
  total_clicks     Decimal?      @default(0) @db.Decimal
  publisher_earned Decimal?      @db.Decimal
  total_credits    Decimal?      @default(0) @db.Decimal
  ad_type          ad_type?      @relation(fields: [type], references: [id])
  ads_devices      ads_devices[]
} 


const campaigns = await prisma.ads.findMany({
        select: {
            id: true,
            name: true,
            image: true,
            description: true,
            ad_type: true
        },
        orderBy: {
            featured: 'desc'
        },
        where: {
            status: true,
            credits: {
                gt: 0
            },
            AND: [
                {
                    OR: [
                        {
                            geo: {
                                contains: country
                            },
                            geoExclude: false
                        },
                        {
                            geo: {
                                notIn: country
                            },
                            geoExclude: true
                        },
                        {
                            geo: ''
                        }
                    ]
                },
                {
                    OR: [
                        {
                            ads_devices: { none: {} },
                        },
                        {
                            ads_devices:
                            {
                                some:
                                {
                                    name: {
                                        equals: deviceType
                                    },
                                    from: {
                                        gte: deviceVersion
                                    },
                                    OR: [
                                        {
                                            to: {
                                                lte: deviceVersion
                                            }
                                        },
                                        {
                                            to: {
                                                equals: "current"
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    ]
                }]
        }
    })
i
Not seeing a field
points
j
There are no field points in that ads table.
i
Oh, weird. I wonder if points is a property of the
decimal
type? Or perhaps, did you not use
prisma migrate
to produce the schema in your database? What does the database show for the table schema?
or perhaps the
null
here is coming from a point field on
ads_devices
or
ad_type
I'd be interested in knowing what
\d ads
yields in
psql
or
pgAdmin
j
Weird error, some request gets processed. I think something is wrong with the inputs passed to Prisma. still no idea what is points mentioned in that error log.
i
well, is
points
on any table in your schema?
j
In ads, ads_devices there are no points. In ad type. there is a points field, but it is not used in the query.
i
ah but it's in the
select
so maybe it needs to be made nullable on the
ad_type
model?
Copy code
model ad_type {
  ...
  points Decimal? ...
  ...
}
j
oh. missed that
let me try
i
that could be why some get past and some don't as well.
👍 1
j
Fixed: The error was due to some validation error. Which inserted null in the ad_type points. And I have focused on the where part of that query. 🤦‍♂️
🙌 1
i
tsconfig.json::compilerOptions.strictNullChecks := true
?
j
Not that validation (front end validation). The field was required before and later changed to an optional one. which was not updated at the Prisma schema. The front end just puts null in that field (instead of 0).
1
j
Can you open an issue about this please? We should have a much better error message for this that explains better to you what might be going on and where to look.