medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
459 stars 31 forks source link

Nullable upsert field can't be null #211

Closed Linloir closed 9 months ago

Linloir commented 1 year ago

I set a nullable field in my schema as follows:

model foo {
  // ...
  deleteAt    DateTime?
  // ...
}

The generation goes well and an upsert interface containing a nullable deleteAt field is generated as expected.

However something is going wrong inside the parsing engine maybe, and I get an error whenever I try to set that field to null (in cases that I didn't delete that item).

The invoke function is kinda like:

final foo = await PrismaProvider.client.foo.upsert(
  where: FooWhereUniqueInput(
    id: baz,
  ),
  create: FooCreateInput(
    deleteAt: null
  ),
  update: FooUpdateInput(
    deleteAt: NullableDateTimeFieldUpdateOperationsInput(
      set: deleted ? deletedTime : null
    ),
  ),
);

The error message is:

PrismaRequestException (PrismaRequestException: Unable to match input value to any allowed input type for the field. Parse errors: [Unable to match input value to any allowed input type for the field. Parse errors: [Invalid argument type. deleteAt should be of any of the following types: DateTime, Some fields are missing: Expected exactly one field to be present, got 0., Invalid argument type. deleteAt should be of any of the following types: Null], Unable to match input value to any allowed input type for the field. Parse errors: [Invalid argument type. deleteAt should be of any of the following types: DateTime, Some fields are missing: Expected exactly one field to be present, got 0., Invalid argument type. deleteAt should be of any of the following types: Null]])

Linloir commented 1 year ago

Tried changing field type to BigInt and the problem still remains

medz commented 1 year ago

@Linloir see https://github.com/odroe/prisma-dart/issues/212

vfiruz97 commented 1 year ago

+1

medz commented 12 months ago

I have good news, the v4 version is almost finished, it reintroduces the PrismaUnion type (using data type nesting to simulate union-types) and the PrismaNull type, which makes this problem solved, please read #290 for progress