[GH-ISSUE #6912] Where clause transformed without input mapping #19300

Closed
opened 2026-04-15 18:12:28 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @erquhart on GitHub (Dec 20, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6912

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Use a custom database adapter
  2. Set supportsDates: false
  3. Use custom transform methods to map dates to/from something custom, like a number
  4. Use that field in a where clause

Current vs. Expected behavior

Those repro steps aren't super helpful, but the concept is you now have transformed data in the database, and you're using non-transformed values to query. So in this case my date fields in the database are numbers, and I'm querying using strings.

What version of Better Auth are you using?

1.4.7

System info

This isn't setup specific.

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)


Additional context

This is a regression from when adapter configuration like supportsDates started being applied to where clauses, but other relevant adapter config like transformations were not. There may be other effects to this, but currently database operations are haywire if you're transforming values that are affected by supports* config properties.

Originally created by @erquhart on GitHub (Dec 20, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6912 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Use a custom database adapter 2. Set `supportsDates: false` 3. Use custom transform methods to map dates to/from something custom, like a number 4. Use that field in a where clause ### Current vs. Expected behavior Those repro steps aren't super helpful, but the concept is you now have transformed data in the database, and you're using non-transformed values to query. So in this case my date fields in the database are numbers, and I'm querying using strings. ### What version of Better Auth are you using? 1.4.7 ### System info ```bash This isn't setup specific. ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context This is a regression from when adapter configuration like `supportsDates` started being applied to where clauses, but other relevant adapter config like transformations were not. There may be other effects to this, but currently database operations are haywire if you're transforming values that are affected by supports* config properties.
GiteaMirror added the locked label 2026-04-15 18:12:28 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 20, 2025):

It seems you're reporting an issue regarding the transformation of the where clause when using a custom database adapter with Better Auth, specifically under the condition that supportsDates is set to false, and transformations for date fields are not properly mapped.

Next Steps:

  1. Ensure that your custom transform methods are correctly implemented to map both input and output data, particularly for fields used in the where clause.
  2. Check if there are existing issues filed related to this specific behavior and follow up on those, as your case may relate to regression in handling transformations based on adapter configurations.

If this does not resolve your issue, I recommend tagging team members Beka and Max (@bekacru and @ping__) for further assistance.

Is there anything specific you would like to know about configuring Better Auth or custom adapters?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3678033678 --> @better-auth-agent[bot] commented on GitHub (Dec 20, 2025): It seems you're reporting an issue regarding the transformation of the `where` clause when using a custom database adapter with Better Auth, specifically under the condition that `supportsDates` is set to false, and transformations for date fields are not properly mapped. **Next Steps**: 1. Ensure that your custom transform methods are correctly implemented to map both input and output data, particularly for fields used in the `where` clause. 2. Check if there are existing issues filed related to this specific behavior and follow up on those, as your case may relate to regression in handling transformations based on adapter configurations. If this does not resolve your issue, I recommend tagging team members Beka and Max (@bekacru and @ping__) for further assistance. Is there anything specific you would like to know about configuring Better Auth or custom adapters? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 20, 2025):

This is a confirmed regression in Better Auth 1.4.7: the adapter factory applies built-in transformations (like supportsDates, supportsBooleans, supportsJSON, and field name mapping) to where clause values, but does not apply custom input transformation functions (such as customTransformInput or field-specific transform.input hooks) to where clause values. So if your adapter transforms date fields to numbers, the where clause will not be mapped using the same transformation, causing mismatches and failed queries—like querying with a string when the DB stores a number. This behavior is visible in the code for transformWhereClause, which only applies basic type conversions and schema-aware mappings, but not custom transforms (source).

Workarounds until a fix lands: manually transform your query values before passing them to Better Auth, or patch your adapter to apply the same transformation logic to where clauses as you do for input data (source). Maintainers have acknowledged the issue and a fix is in progress, but as of 1.4.7, this is not yet addressed in the main changelog or stable release. This can cause unpredictable database operations when using custom data transformations with supports* config properties (source).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3678035648 --> @dosubot[bot] commented on GitHub (Dec 20, 2025): <!-- Answer --> This is a confirmed regression in Better Auth 1.4.7: the adapter factory applies built-in transformations (like `supportsDates`, `supportsBooleans`, `supportsJSON`, and field name mapping) to where clause values, but does **not** apply custom input transformation functions (such as `customTransformInput` or field-specific `transform.input` hooks) to where clause values. So if your adapter transforms date fields to numbers, the where clause will not be mapped using the same transformation, causing mismatches and failed queries—like querying with a string when the DB stores a number. This behavior is visible in the code for `transformWhereClause`, which only applies basic type conversions and schema-aware mappings, but not custom transforms ([source](https://github.com/better-auth/better-auth/blob/4551e095a119037b7caa14f680d4f2c4c5d63e78/packages/core/src/db/adapter/factory.ts#L182-L1244)). Workarounds until a fix lands: manually transform your query values before passing them to Better Auth, or patch your adapter to apply the same transformation logic to where clauses as you do for input data ([source](https://github.com/better-auth/better-auth/issues/4805#issuecomment-3316272473)). Maintainers have acknowledged the issue and a fix is in progress, but as of 1.4.7, this is not yet addressed in the main changelog or stable release. This can cause unpredictable database operations when using custom data transformations with `supports*` config properties ([source](https://github.com/better-auth/better-auth/issues/3892#issuecomment-3170464388)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/02e64bf3-c542-4a0a-bed7-ca25771642f6?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20confirmed%20regression%20in%20Better%20Auth%201.4.7%3A%20the%20adapter%20factory%20applies%20built-in%20transformations%20%28like%20%60supportsDates%60%2C%20%60supportsBooleans%60%2C%20%60supportsJSON%60%2C%20and%20field%20name%20mapping%29%20to%20where%20clause%20values%2C%20but%20does%20%2A%2Anot%2A%2A%20apply%20custom%20input%20transformation%20functions%20%28such%20as%20%60customTransformInput%60%20or%20field-specific%20%60transform.input%60%20hooks%29%20to%20where%20clause%20values.%20So%20if%20your%20adapter%20transforms%20date%20fields%20to%20numbers%2C%20the%20where%20clause%20will%20not%20be%20mapped%20using%20the%20same%20transformation%2C%20causing%20mismatches%20and%20failed%20queries%E2%80%94like%20querying%20with%20a%20string%20when%20the%20DB%20stores%20a%20number.%20This%20behavior%20is%20visible%20in%20the%20code%20for%20%60transformWhereClause%60%2C%20which%20only%20applies%20basic%20type%20conversions%20and%20schema-aware%20mappings%2C%20but%20not%20custom%20transforms%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/4551e095a119037b7caa14f680d4f2c4c5d63e78/packages/core/src/db/adapter/factory.ts%23L182-L1244%29%29.%0A%0AWorkarounds%20until%20a%20fix%20lands%3A%20manually%20transform%20your%20query%20values%20before%20passing%20them%20to%20Better%20Auth%2C%20or%20patch%20your%20adapter%20to%20apply%20the%20same%20transformation%20logic%20to%20where%20clauses%20as%20you%20do%20for%20input%20data%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4805%23issuecomment-3316272473%29%29.%20Maintainers%20have%20acknowledged%20the%20issue%20and%20a%20fix%20is%20in%20progress%2C%20but%20as%20of%201.4.7%2C%20this%20is%20not%20yet%20addressed%20in%20the%20main%20changelog%20or%20stable%20release.%20This%20can%20cause%20unpredictable%20database%20operations%20when%20using%20custom%20data%20transformations%20with%20%60supports%2A%60%20config%20properties%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/3892%23issuecomment-3170464388%29%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6912)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19300