Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: GeneratedAlwaysAs #3511

Closed
1 task done
jtidwe11 opened this issue Nov 8, 2024 · 2 comments
Closed
1 task done

[BUG]: GeneratedAlwaysAs #3511

jtidwe11 opened this issue Nov 8, 2024 · 2 comments
Labels
bug Something isn't working drizzle/zod

Comments

@jtidwe11
Copy link

jtidwe11 commented Nov 8, 2024

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.0

What version of drizzle-kit are you using?

0.28.0

Other packages

drizzle-zod@0.5.1

Describe the Bug

Playground: https://drizzle.run/tnqgqasce82gq05mipu7whwm

The above drizzle-kit version may not be accurate - I didn't see a way to view it in the playground. Applies at least to both SQLite and Postgres.

Generated columns should not accept a value for an insert nor should they be altered directly. However, the insert schema generated from the playground returns an object of all 5 columns as optional; parsing or safe-parsing the object sets the value given as if ignored. Drizzle does properly ignore those columns when inserting, but passing the object to said function returns no errors.

I would think that one at least one of the following should have happened:

  1. The createInsertSchema function does not return the generated columns or they are returned as ZodReadOnly
  2. The parse function throws an error for unknown properties
  3. Drizzle throws an error when an object passed to values does not meet the criteria

If the above cannot be done, could we add a readOnly or similar that would otherwise enforce this? In SQL Server, you have to explicitly call IDENTITY INSERT OFF, for example to insert values into an identity column. I know it's not quite the same, but I need a way to generate values without worrying about rogue actors. The solution to this (however it comes to be) could be a good candidate for the eslint plugin as well.

As an aside, the much simpler example from docs does not work. I've commented the errors I received in the playground. Since I can replicate it otherwise and it's out of scope, I didn't check to see if they already existed in the issue list. I can add those separately if needed.

@jtidwe11 jtidwe11 added the bug Something isn't working label Nov 8, 2024
@aldebout
Copy link

Adding for more impact use cases: I have a not-null generated column, so I need to manually omit is from the createInsertSchema result otherwise it wreaks havoc on my input validation.

@AndriiSherman
Copy link
Member

This one was fixed in the latest for all validator packages
drizzle-zod@0.6.0
drizzle-valibot@0.3.0
drizzle-typebox@0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle/zod
Projects
None yet
Development

No branches or pull requests

4 participants