Skip to content

fix(@db.Date): accept plain date strings in DateTime @db.Date field filters#2572

Open
lsmith77 wants to merge 3 commits intozenstackhq:devfrom
lsmith77:plain-date
Open

fix(@db.Date): accept plain date strings in DateTime @db.Date field filters#2572
lsmith77 wants to merge 3 commits intozenstackhq:devfrom
lsmith77:plain-date

Conversation

@lsmith77
Copy link
Copy Markdown
Contributor

@lsmith77 lsmith77 commented Apr 9, 2026

  • all Date/Datetime fields now accept plain date strings ("2007-05-23") in equality and comparison filters
  • ISO datetime strings still work
  • Date objects still work
  • Invalid strings are still rejected

Summary by CodeRabbit

  • New Features

    • DateTime handling extended: date-only fields now accept plain YYYY-MM-DD strings in filters and write payloads, while non-date-only DateTime fields continue to require ISO/Date formats.
  • Tests

    • Added end-to-end tests verifying schema validation accepts plain date strings where applicable and that queries using those strings return correct results for create, update, and find operations.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 550646b6-c70c-41ee-a574-324cf100a7c0

📥 Commits

Reviewing files that changed from the base of the PR and between bd695df and f168be8.

📒 Files selected for processing (2)
  • packages/orm/src/client/zod/factory.ts
  • tests/e2e/orm/client-api/db-date-filter.test.ts
✅ Files skipped from review due to trivial changes (1)
  • tests/e2e/orm/client-api/db-date-filter.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/orm/src/client/zod/factory.ts

📝 Walkthrough

Walkthrough

DateTime Zod schemas were widened to accept ISO date strings (YYYY-MM-DD) for fields annotated with @db.Date and filter schemas; a new E2E Vitest verifies schema validation and runtime filtering/CRUD behavior for @db.Date and regular DateTime fields.

Changes

Cohort / File(s) Summary
Zod factory
packages/orm/src/client/zod/factory.ts
Added hasAttribute(attributes, name) helper; widened DateTime value schema and filter schemas to include z.iso.date() alongside existing ISO datetime and Date representations for @db.Date handling.
E2E tests
tests/e2e/orm/client-api/db-date-filter.test.ts
Added Vitest e2e tests that provision a Postgres test client from an inline schema with eventDate DateTime @db.Date``; validate makeFindManySchema, `makeCreateSchema`, and `makeUpdateSchema` accept plain `YYYY-MM-DD` strings where appropriate and assert runtime filtering/CRUD behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I hopped through schemas, found a new way,
YYYY‑MM‑DD joins the ISO play.
Filters now welcome the plain date song,
Tests clap along as records get along.
Carrots for code, quick hops all day. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: enabling plain date string acceptance in DateTime @db.Date field filters, which is the core objective of the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/e2e/orm/client-api/db-date-filter.test.ts (1)

30-33: Remove unnecessary writes in schema-only validation test.

This case only checks safeParse, so the two create calls are not needed and add E2E runtime overhead.

♻️ Optional cleanup
 it('accepts a plain date string ("YYYY-MM-DD") in an equality filter on a `@db.Date` field', async () => {
-    await client.event.create({ data: { name: 'Conference', eventDate: new Date('2007-05-23') } });
-    await client.event.create({ data: { name: 'Workshop', eventDate: new Date('2024-01-15') } });
-
     const filterSchema = client.$zod.makeFindManySchema('Event');
     const result = filterSchema.safeParse({ where: { eventDate: '2007-05-23' } });
     expect(result.success, `Expected plain date string to be accepted, got: ${JSON.stringify(result.error)}`).toBe(
         true,
     );
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/orm/client-api/db-date-filter.test.ts` around lines 30 - 33, The
test "accepts a plain date string (\"YYYY-MM-DD\") in an equality filter on a
`@db.Date` field" currently performs two unnecessary writes via
client.event.create; remove the two await client.event.create(...) lines so the
test only performs schema-only validation (safeParse) to avoid E2E runtime
overhead—keep the rest of the test intact and ensure any references to those
created records are also removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/e2e/orm/client-api/db-date-filter.test.ts`:
- Around line 30-33: The test "accepts a plain date string (\"YYYY-MM-DD\") in
an equality filter on a `@db.Date` field" currently performs two unnecessary
writes via client.event.create; remove the two await client.event.create(...)
lines so the test only performs schema-only validation (safeParse) to avoid E2E
runtime overhead—keep the rest of the test intact and ensure any references to
those created records are also removed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e4bbe47-96a5-49d9-9aa8-a631eaa38b88

📥 Commits

Reviewing files that changed from the base of the PR and between 39a0a28 and e900bb6.

📒 Files selected for processing (2)
  • packages/orm/src/client/zod/factory.ts
  • tests/e2e/orm/client-api/db-date-filter.test.ts

@ymc9
Copy link
Copy Markdown
Member

ymc9 commented Apr 13, 2026

Hi @lsmith77 , thanks for working on this. Since the change is only related to filtering, I think we can unconditionally support it for DateTime field (regardless if it carries db.Date). This also helps decouples ORM runtime and the migration engine (db.xxx attributes are only used by migrations).

What do you think?

@lsmith77 lsmith77 force-pushed the plain-date branch 2 times, most recently from 4234f76 to bd695df Compare April 14, 2026 06:49
@lsmith77
Copy link
Copy Markdown
Contributor Author

I made the necessary changes.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/orm/src/client/zod/factory.ts`:
- Line 855: The shared makeDateTimeValueSchema (used via
makeScalarSchema('DateTime')) currently includes z.iso.date(), which
unintentionally permits plain date strings everywhere; remove z.iso.date() from
the union in makeDateTimeValueSchema so the shared DateTime scalar only accepts
Date objects and ISO datetimes (keep z.date() and z.iso.datetime()), and instead
add z.iso.date() only at the field/filter-specific validation code that handles
`@db.Date` filters (i.e., where field-level or filter-level schemas are created),
so date-only strings are accepted only for `@db.Date` contexts.

In `@tests/e2e/orm/client-api/db-date-filter.test.ts`:
- Around line 76-82: The test "plain date string is accepted on a regular
DateTime field (no `@db.Date`)" contradicts the intended behavior; update the test
so the filter schema for Event (created via
client.$zod.makeFindManySchema('Event')) rejects a plain 'YYYY-MM-DD' string for
the createdAt DateTime field: call filterSchema.safeParse({ where: { createdAt:
'2007-05-23' } }) and assert result.success is false (or assert that parsing
fails/throws), ensuring the expectation aligns with the non-@db.Date rule.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5e4dc56c-2518-44a2-b2ba-a904456d85c6

📥 Commits

Reviewing files that changed from the base of the PR and between 4234f76 and bd695df.

📒 Files selected for processing (2)
  • packages/orm/src/client/zod/factory.ts
  • tests/e2e/orm/client-api/db-date-filter.test.ts

Comment thread packages/orm/src/client/zod/factory.ts Outdated
@cache()
private makeDateTimeValueSchema(): ZodType {
const schema = z.union([z.iso.datetime(), z.date()]);
const schema = z.union([z.iso.date(), z.iso.datetime(), z.date()]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Scope regression: this change accepts plain date strings globally, not only @db.Date filters.

makeDateTimeValueSchema() is shared via makeScalarSchema('DateTime'), so adding z.iso.date() expands acceptance beyond the intended filter-only @db.Date case (including regular DateTime and mutation input validation paths). Please gate date-only acceptance at the field/filter level instead of the shared scalar DateTime value schema.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/orm/src/client/zod/factory.ts` at line 855, The shared
makeDateTimeValueSchema (used via makeScalarSchema('DateTime')) currently
includes z.iso.date(), which unintentionally permits plain date strings
everywhere; remove z.iso.date() from the union in makeDateTimeValueSchema so the
shared DateTime scalar only accepts Date objects and ISO datetimes (keep
z.date() and z.iso.datetime()), and instead add z.iso.date() only at the
field/filter-specific validation code that handles `@db.Date` filters (i.e., where
field-level or filter-level schemas are created), so date-only strings are
accepted only for `@db.Date` contexts.

Comment thread tests/e2e/orm/client-api/db-date-filter.test.ts Outdated
@lsmith77
Copy link
Copy Markdown
Contributor Author

wait .. I need to do some more cleanups in the tests.

@lsmith77
Copy link
Copy Markdown
Contributor Author

ok no. I think all is well. CodeRabbit appears to be confused because of the change of scope of this PR. not sure how to tell CodeRabbit to deal with that.

@lsmith77
Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
packages/orm/src/client/zod/factory.ts (1)

855-867: ⚠️ Potential issue | 🟠 Major

Keep plain-date support filter-scoped instead of broadening the shared DateTime scalar.

Line 855 adds z.iso.date() to makeDateTimeValueSchema(), but this schema is shared via makeScalarSchema('DateTime') and is reused outside filters (e.g., create/update/procedure params). That widens accepted inputs beyond filter parsing.

Suggested change
 private makeDateTimeValueSchema(): ZodType {
-    const schema = z.union([z.iso.date(), z.iso.datetime(), z.date()]);
+    const schema = z.union([z.iso.datetime(), z.date()]);
     this.registerSchema('DateTime', schema);
     return schema;
 }

+private makeDateTimeFilterValueSchema(): ZodType {
+    return z.union([z.iso.date(), z.iso.datetime(), z.date()]);
+}

 private makeDateTimeFilterSchema(
@@
-        const schema = this.makeCommonPrimitiveFilterSchema(
-            this.makeDateTimeValueSchema(),
+        const schema = this.makeCommonPrimitiveFilterSchema(
+            this.makeDateTimeFilterValueSchema(),
             optional,
             () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)),
             withAggregations ? ['_count', '_min', '_max'] : undefined,
             allowedFilterKinds,
         );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/orm/src/client/zod/factory.ts` around lines 855 - 867, The shared
DateTime scalar (created via makeDateTimeValueSchema and registered in
makeScalarSchema('DateTime')) was broadened by adding z.iso.date(), which
incorrectly allows plain-date inputs outside filters; remove z.iso.date() from
makeDateTimeValueSchema so the shared scalar only accepts the intended
datetime/date types, and instead add plain-date support only inside the filter
pipeline by adjusting makeDateTimeFilterSchema to accept an additional union
that includes z.iso.date() (e.g., compose the filter value schema as
z.union([z.iso.date(), this.makeDateTimeValueSchema()]) before passing it into
makeCommonPrimitiveFilterSchema) so filters get plain-date support without
changing the global DateTime scalar.
🧹 Nitpick comments (1)
tests/e2e/orm/client-api/db-date-filter.test.ts (1)

63-63: Test name says gt/lt, but only gt is exercised.

Either rename the test to gt only or add an lt assertion for parity.

Possible rename
-it('supports gt/lt filters with plain date strings on a `@db.Date` field', async () => {
+it('supports gt filters with plain date strings on a `@db.Date` field', async () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/orm/client-api/db-date-filter.test.ts` at line 63, The test
"supports gt/lt filters with plain date strings on a `@db.Date` field" only
exercises the gt case; update the test to match its name by adding an lt
assertion (mirror the existing gt assertion using a less-than filter on the same
`@db.Date` field) or rename the it(...) description to "supports gt filters with
plain date strings on a `@db.Date` field"; locate the it block in
db-date-filter.test.ts and either add the corresponding lt filter assertion or
adjust the string literal in the it(...) call to reflect only gt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/orm/src/client/zod/factory.ts`:
- Around line 855-867: The shared DateTime scalar (created via
makeDateTimeValueSchema and registered in makeScalarSchema('DateTime')) was
broadened by adding z.iso.date(), which incorrectly allows plain-date inputs
outside filters; remove z.iso.date() from makeDateTimeValueSchema so the shared
scalar only accepts the intended datetime/date types, and instead add plain-date
support only inside the filter pipeline by adjusting makeDateTimeFilterSchema to
accept an additional union that includes z.iso.date() (e.g., compose the filter
value schema as z.union([z.iso.date(), this.makeDateTimeValueSchema()]) before
passing it into makeCommonPrimitiveFilterSchema) so filters get plain-date
support without changing the global DateTime scalar.

---

Nitpick comments:
In `@tests/e2e/orm/client-api/db-date-filter.test.ts`:
- Line 63: The test "supports gt/lt filters with plain date strings on a
`@db.Date` field" only exercises the gt case; update the test to match its name by
adding an lt assertion (mirror the existing gt assertion using a less-than
filter on the same `@db.Date` field) or rename the it(...) description to
"supports gt filters with plain date strings on a `@db.Date` field"; locate the it
block in db-date-filter.test.ts and either add the corresponding lt filter
assertion or adjust the string literal in the it(...) call to reflect only gt.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 716fb41f-22c6-4d38-bfae-be3a20ef60db

📥 Commits

Reviewing files that changed from the base of the PR and between ad8d5fb and bd695df.

📒 Files selected for processing (2)
  • packages/orm/src/client/zod/factory.ts
  • tests/e2e/orm/client-api/db-date-filter.test.ts

@lsmith77
Copy link
Copy Markdown
Contributor Author

lsmith77 commented Apr 14, 2026

I added a follow-up in f168be8 that allows plain YYYY-MM-DD strings for create/update payloads on DateTime @db.Date fields, while keeping regular DateTime fields unchanged.

Before I leave that in this PR, do you want this extra behavior change here, or would you prefer to keep this PR limited to filter support only and handle @db.Date write-path support separately?

@ymc9
Copy link
Copy Markdown
Member

ymc9 commented Apr 15, 2026

I added a follow-up in f168be8 that allows plain YYYY-MM-DD strings for create/update payloads on DateTime @db.Date fields, while keeping regular DateTime fields unchanged.

Before I leave that in this PR, do you want this extra behavior change here, or would you prefer to keep this PR limited to filter support only and handle @db.Date write-path support separately?

I think it's fine to include such support for mutation too. Time portion will be zeroed which should be intuitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants