[BUG]: drizzle-zod when using coerce: true maps `float` as `int` and vice versa

Open Beginner friendly
#4,572 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
databases

Research direction

Start in drizzle-zod/src/column.ts around line 244 and reproduce the reported createSchemaFactory({ coerce: true }) case with a PostgreSQL doublePrecision column. Check the generated schema's number handling; done when a float value such as 5.5 parses correctly while integer columns still enforce integer values.

Written by the indexing model from the issue text.

Description

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

drizzle-zod 0.8.2

Describe the Bug
const test = pgTable("test", {
  float: doublePrecision(),
});

const { createSelectSchema } = createSchemaFactory({
  coerce: true,
});

const schema = createSelectSchema(test);
schema.parse({ float: 5.5 }); // error thrown here

In this case float field in schema will be integer because of wrong ternary operator here:
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-zod/src/column.ts#L244

integer ? z.coerce.number() : z.coerce.number().int()

Number field is returned when column type is int and vice versa(int returned when actual type is float)

Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
1d 13h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from drizzle-team/drizzle-orm

All issues in drizzle-team/drizzle-orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.