zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

[Bug] Optimistic updates and undefined in @zenstackhq/tanstack-query plug-in

Open ellie-xpawn opened this issue 2 months ago • 1 comments

Description and expected behavior I'm using the optimistic update flag in my mutation useUpdate[model]({ optimisticUpdate: true }), and when I pass undefined to a field, it is getting stored in the cache - Prisma will ignore a field if it is set to undefined, so it won't update in the DB. This doesn't happen when the data is initially fetched from the server.

There is an easy workaround in this case, as I only have one field to update. I can just pass an empty object if my value is undefined.

Screenshots

Image Image

query.data affected by the mutation logged to console: Image

Environment (please complete the following information):

  • ZenStack version: 2.21.0
  • Prisma version: 6.17.1
  • Database type: Postgres (Neon)

ellie-xpawn avatar Oct 30 '25 23:10 ellie-xpawn

Workaround: not passing undefined

Image

This prevents any errors from occurring.

ellie-xpawn avatar Oct 30 '25 23:10 ellie-xpawn

Hi @ellie-xpawn , I can't seem to reproduce the issue. Do you have a shareable project?

ymc9 avatar Nov 22 '25 01:11 ymc9

No, sorry. I forgot to mention earlier that ActivityProgress is extended by other models (ie. TestActivityProgress) - maybe the issue is related to polymorphism?

ellie-xpawn avatar Nov 24 '25 17:11 ellie-xpawn