-
-
Notifications
You must be signed in to change notification settings - Fork 688
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]: Mismatched type hints when using RDS Data API #2097
Comments
I seem to have just hit this bug, which results in my I'm using v0.30.7. |
@AndriiSherman @AlexBlokh I would be willing to help move this forward just wondering if you have had thoughts on the approach and why typings weren't initially passed around with the actual params? |
@dankochetov I see you were working on some data api fixes in #2119 do you have thoughts on the best approach here ? |
@cmanou could you provide an example query that triggers this behavior? |
I know this is a description rather than an example, but I believe it occurs any time you have a query that will generate a list of parameters where some parameters do not have type hints, followed by parameters which do have type hints. The type hints then get associated with the earlier parameters instead of the correct ones. |
Lots off different ones this particular one was:
|
I'm pretty confident in the |
@dankochetov Have you had anymore thoughts on this? Happy to help if you have a particular direction. |
@dankochetov Just wondering if you have had anymore thoughts on this it basically makes data api un-usuable which is a shame. As I said I'm willing to work on the sulotion just wondering if you had a preference on the approach ie allow undefined or pass the hints with their values all the way through? |
Okay based off the brief discussion in discord theoretically this shouldn't be happening because the typings should be filled with 'none' type but it turns out for placeholders and cases where drizzle builds internal params such as for relationships
the type isn't add in these too lines drizzle-orm/drizzle-orm/src/sql/sql.ts Line 220 in 0ddab65
drizzle-orm/drizzle-orm/src/sql/sql.ts Line 251 in 0ddab65
Updating them to have ['none'] as the types resolves the issue but feels incorrect as really we should be trying to use |
@zacronos could you test if it works with |
If I had a convenient query, I would love to help -- unfortunately I've entirely forgotten which query was the source of the problem for me, and we're swamped with customer onboarding at the moment. |
should be fixed in |
@AndriiSherman Thanks for jumping on this, but I'm still facing an issue with I also narrowed down the issue to the function mergeQueries(queries: QueryWithTypings[]): QueryWithTypings {
const result: QueryWithTypings = { sql: '', params: [] };
for (const query of queries) {
result.sql += query.sql;
result.params.push(...query.params);
if (query.typings?.length) {
if (!result.typings) {
// setting an array of "none" for possible prior params
// without typing resolves the issue for me:
result.typings = new Array(result.params.length - query.params.length).fill("none");
}
result.typings.push(...query.typings);
}
}
return result;
} Logged query in my case: SELECT
"stations"."id",
"stations"."external_id",
"stations"."name",
"stations"."latitude",
"stations"."longitude",
"stations"."operator_id",
"stations"."created_at",
"stations"."updated_at",
"stations_operator"."data" AS "operator",
"stations_evses"."data" AS "evses"
FROM "stations"
LEFT JOIN LATERAL (
SELECT json_build_array(
"stations_operator"."id",
"stations_operator"."name",
"stations_operator"."last_imported"
) AS "data"
FROM (
SELECT * FROM "operators" "stations_operator"
WHERE "stations_operator"."id" = "stations"."operator_id"
LIMIT :1
) "stations_operator"
) "stations_operator" ON true
LEFT JOIN LATERAL (
SELECT coalesce(
json_agg(
json_build_array(
"stations_evses"."uid",
"stations_evses"."operator_id",
"stations_evses"."evse_id",
"stations_evses"."station",
"stations_evses"."updated_at",
"stations_evses_connectors"."data"
)
), '[]'::json
) AS "data"
FROM "evses" "stations_evses"
LEFT JOIN LATERAL (
SELECT coalesce(
json_agg(
json_build_array(
"stations_evses_connectors"."id",
"stations_evses_connectors"."operator_id",
"stations_evses_connectors"."evse_uid",
"stations_evses_connectors"."standard",
"stations_evses_connectors"."max_voltage",
"stations_evses_connectors"."max_amperage",
"stations_evses_connectors"."updated_at"
)
), '[]'::json
) AS "data"
FROM "connectors" "stations_evses_connectors"
WHERE (
"stations_evses_connectors"."evse_uid" = "stations_evses"."uid"
AND "stations_evses_connectors"."operator_id" = "stations_evses"."operator_id"
)
) "stations_evses_connectors" ON true
WHERE "stations_evses"."station" = "stations"."id"
) "stations_evses" ON true
WHERE (
"stations"."external_id" = :2
AND "stations"."operator_id" = :3
AND "stations"."updated_at" < :4
)
LIMIT :5;
-- params: [
-- {
-- "name": "1",
-- "value": {
-- "longValue": 1
-- }
-- },
-- {
-- "name": "2",
-- "value": {
-- "stringValue": "S104"
-- },
-- "typeHint": "UUID" --> should be typing of param "3"
-- },
-- {
-- "name": "3",
-- "value": {
-- "stringValue": "1ca49824-d2cb-4bc1-96de-af8b3d68be12"
-- },
-- "typeHint": "TIMESTAMP" --> should be typing of param "4"
-- },
-- {
-- "name": "4",
-- "value": {
-- "stringValue": "2024-07-22T08:39:59.943Z"
-- }
-- },
-- {
-- "name": "5",
-- "value": {
-- "longValue": 1
-- }
-- }
-- ] const data = await db.query.stations.findFirst({
where: (stations) => {
return and(
eq(stations.externalId, ids.location_id),
eq(stations.operatorId, ids.operator_id),
lt(stations.updatedAt, new Date()), // Only return if the station is not updated
);
},
with: {
operator: true,
evses: {
with: {
connectors: true,
},
},
},
}); |
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
When using AwsDataApi pg driver which actually makes use of the type hints, there has been a bunch of queries that have resulted in mismatched hints. I have narrowed down the issue to the
mergeQueries
function insql.ts
drizzle-orm/drizzle-orm/src/sql/sql.ts
Line 69 in 0ddab65
This results in
Which has the typings indexes incorrect for when they are used later on by the dataapi session driver.
Expected behavior
Expected the result from merge queries to be similar to this, or potentially but would require more work is making it such that the typings stick with the params?
Environment & setup
No response
The text was updated successfully, but these errors were encountered: