-
-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: Type error with postgresjs strings/dates in version 0.30 #1993
Comments
I am having the same issue on version |
@gp27 Please keep me posted if you find a solution or workaround for this. I'm surprised that more people don't appear to be experiencing this since it's such a basic use case, so I feel like I must be overlooking something obvious. |
Quick update - I've narrowed down the source of the issue to instances where a date is passed to the It still works to pass a date to a filter operator (e.g. The workaround that worked for me for now is to convert any dates used with the |
I tried to investigate this issue further. When the parsers for timezone related types were switched, so were the serializers: The replacements of those serializers is probably what is causing this issue and #2009 as well. I am not sure it was necessary to replace the serialziers as well, since the issue was on the parsing side, but I may be wrong. Maybe @Angelelz who authored the fix might have some further info about it. |
The replacement of the serializer and parsers was necessary to guarantee that the same parsing/serializer code from Drizzle will work for both postgres.js and node-PG interchangeably. Unfortunately I have very little time lately to dedicate to drizzle but if somebody puts together a quick reproduction it will make it easier to investigate/fix. |
Until this is solved, a temporary workaround is to create a custom type: import { customType } from "drizzle-orm/pg-core"
export const customDate = customType<{
data: string
driverData: Date
}>({
dataType() {
return "date"
},
fromDriver(value: Date): string {
return value.toISOString().slice(0, 10)
},
}) |
What version of
drizzle-orm
are you using?0.30.1
What version of
drizzle-kit
are you using?0.20.14
Describe the Bug
I'm using Drizzle with postgresjs and recently updated to v0.30.1, where I know the driver was updated to always return strings for dates.
Many of my queries then failed with an error
ERR_INVALID_ARG_TYPE
:The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Date"
.Here's an example of a failed query that produced that error message:
Where
sessions.timestamp
is defined astimestamp('timestamp', { mode: 'date', withTimezone: true })
in my schema.When I convert
startDate
to a string with.toISOString()
, the query works, but I get the following type error:Any tips would be appreciated. Thank you!
Expected behavior
No response
Environment & setup
No response
The text was updated successfully, but these errors were encountered: