[PR #5182] [MERGED] fix: ensure falsy values are valid default values #5831

Closed
opened 2026-03-13 12:38:01 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5182
Author: @ocherry341
Created: 10/9/2025
Status: Merged
Merged: 10/9/2025
Merged by: @Bekacru

Base: canaryHead: fix/parse-input-data


📝 Commits (1)

  • 2b3a001 fix(parse-input-data): ensure falsy values are valid default values

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/db/schema.ts (+2 -2)

📄 Description

What's Changed and Why

This PR resolves a bug where fields with a falsy defaultValue, specifically 0 or an empty string (""), were incorrectly skipped during the data parsing process.

Relevant Context or Background

This validation logic is crucial for ensuring that field configurations are respected when initializing data for new resources. Incorrectly skipping 0 or "" as default values can lead to unexpected behavior in downstream logic that depends on these fields being present or having their configured default, rather than being entirely absent.

Breaking Changes or Deprecations

None.


Summary by cubic

Fixes parseInputData so falsy default values (0 and "") are applied instead of skipped. This ensures fields initialize with their configured defaults when input is disabled or on create.

  • Bug Fixes
    • Use defaultValue !== undefined instead of a truthy check in both branches of parseInputData.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5182 **Author:** [@ocherry341](https://github.com/ocherry341) **Created:** 10/9/2025 **Status:** ✅ Merged **Merged:** 10/9/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/parse-input-data` --- ### 📝 Commits (1) - [`2b3a001`](https://github.com/better-auth/better-auth/commit/2b3a001e7d822b85e8d20cffc35332bab85a6c66) fix(parse-input-data): ensure falsy values are valid default values ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/schema.ts` (+2 -2) </details> ### 📄 Description ### What's Changed and Why This PR resolves a bug where fields with a **falsy** `defaultValue`, specifically `0` or an empty string (`""`), were incorrectly skipped during the data parsing process. ### Relevant Context or Background This validation logic is crucial for ensuring that field configurations are respected when initializing data for new resources. Incorrectly skipping `0` or `""` as default values can lead to unexpected behavior in downstream logic that depends on these fields being present or having their configured default, rather than being entirely absent. ### Breaking Changes or Deprecations None. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes parseInputData so falsy default values (0 and "") are applied instead of skipped. This ensures fields initialize with their configured defaults when input is disabled or on create. - **Bug Fixes** - Use `defaultValue !== undefined` instead of a truthy check in both branches of parseInputData. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:38:01 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5831