Skip to content

fix(datasource-sequelize): serialize Dateonly fields as YYYY-MM-DD format#1442

Merged
Scra3 merged 2 commits into
mainfrom
fix/dateonly-composite-primary-key
Feb 3, 2026
Merged

fix(datasource-sequelize): serialize Dateonly fields as YYYY-MM-DD format#1442
Scra3 merged 2 commits into
mainfrom
fix/dateonly-composite-primary-key

Conversation

@Scra3

@Scra3 Scra3 commented Feb 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix serialization of Dateonly fields to use YYYY-MM-DD format instead of full ISO timestamp
  • This fixes an issue where composite primary keys containing DATEONLY fields caused detail page lookups to fail

Problem

When a DATEONLY field is part of a composite primary key, the ID was being generated incorrectly:

  • Generated: 1|group-123|2025-01-15T00:00:00.000Z
  • Expected: 1|group-123|2025-01-15

Solution

The Serializer class now checks the field type from the model's rawAttributes and formats Dateonly fields as YYYY-MM-DD.

Test plan

  • Added unit tests for Dateonly field serialization
  • Added unit tests for Date field serialization (unchanged behavior)
  • Added unit tests for mixed Date/Dateonly fields
  • Added unit tests for arrays of date values
  • Build passes
  • Lint passes

Fixes #1441

🤖 Generated with Claude Code

@qltysh

qltysh Bot commented Feb 2, 2026

Copy link
Copy Markdown

Qlty

Coverage Impact

⬆️ Merging this pull request will increase total coverage on main by 0.01%.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/datasource-sequelize/src/collection.ts100.0%
Coverage rating: A Coverage rating: A
packages/datasource-sequelize/src/utils/serializer.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@Scra3 Scra3 force-pushed the fix/dateonly-composite-primary-key branch from 16d7a06 to 2eda6d3 Compare February 2, 2026 13:01
@qltysh

qltysh Bot commented Feb 2, 2026

Copy link
Copy Markdown

All good ✅

@Scra3 Scra3 force-pushed the fix/dateonly-composite-primary-key branch 2 times, most recently from 0a5cb5a to 5cde0df Compare February 2, 2026 13:13
…rmat

Dateonly fields in composite primary keys were being serialized with the
full ISO timestamp (2025-01-15T00:00:00.000Z) instead of just the date
(2025-01-15), causing detail page lookups to fail.

The serializer now checks the field type and formats Dateonly fields
correctly.

Fixes #1441

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Scra3 Scra3 force-pushed the fix/dateonly-composite-primary-key branch from 5cde0df to 47c8f7c Compare February 2, 2026 13:16
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
if (value instanceof Date) {
const typeKey = (rawAttributes?.[name]?.type as { key?: string })?.key;
const iso = this.serializeDate(value);
record[name] = typeKey === DataTypes.DATEONLY.key && iso ? iso.slice(0, 10) : iso;

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.

here iso will be the result of serializeDate compared to before it was serializeValue.
What is the difference between both ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Code should be refactored, but in our case we can call directly the serializeDate method :)

@Scra3

Scra3 commented Feb 3, 2026

Copy link
Copy Markdown
Member Author

linked to this issue: #1441

@Scra3 Scra3 merged commit db7b967 into main Feb 3, 2026
25 checks passed
@Scra3 Scra3 deleted the fix/dateonly-composite-primary-key branch February 3, 2026 10:47
forest-bot added a commit that referenced this pull request Feb 3, 2026
## @forestadmin/datasource-sequelize [1.13.2](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/datasource-sequelize@1.13.1...@forestadmin/datasource-sequelize@1.13.2) (2026-02-03)

### Bug Fixes

* **datasource-sequelize:** serialize Dateonly fields as YYYY-MM-DD format ([#1442](#1442)) ([db7b967](db7b967)), closes [#1441](#1441)
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.

DATEONLY field in composite primary key causes detail page error due to inconsistent date format

2 participants