-
Notifications
You must be signed in to change notification settings - Fork 38
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
Cannot save null values: Cannot convert undefined or null to object #83
Comments
Hi, I have a one to one relationship between two tables. In a simplified version:
I'm trying to delete any row in RefreshTokenEntity linked to a specific user. As per typeorm documentation, I'm using set(null) to do this:
However I get this error (the stack trace looks similar to the one you have @clalexander):
Thanks for your insight! |
@ArnaudDutant Looks to be the same error to me. |
Should be fixed in 2.1.1, please let me know if you have more issues with it. |
Still seeing this error when used with Postgres. @ArsenyYankovsky Looking into it now. My first assumption is that you should be able to pass in undefined as a parameter and the query should basically just drop that param. i.e. do not set it to null. However, it seems like the undefined param is getting passed all the way day to the data API lib and then crashes there. I'm not sure if the driver should be dealing with this, or if it's upstream in TypeORM. My guess is that it should be getting taken care of upstream. So that by the time we get the query string and parameters it is already omited. I could be wrong though. Thoughts? |
I think we need to check where undefined is handled when using the "normal" MySQL/Postgres drivers and try to replicate similar behavior. |
For me with version 2.2.0 passing a So I'm not sure what the issue could be for you @seawatts. |
I also faced this issue. At least it would be nice to have some proper error description, like what field goes wrong etc... |
I face a similar issue with I can't save empty set. @Column({ type: 'set', enum: enumValues(NetworkType)})
networkType: NetworkType[]; An empty array
The resulting parameter is {
name: "param_1",
value: {
value: '',
},
} which breaks later because it is invalid
|
Issue
Cannot save null values to mysql database. Null query parameter values fail to map correctly in
normalizeParams
, resulting inTypeError: Cannot convert undefined or null to object
Stack Trace
Steps to Reproduce
Package versions and database engine type:
Additional Context
Debug Tracing
First, src/query-transformer/mysql-query-transformer.ts:127
transformParameters(parameters?: any[])
maps allnull
(and undefined) parameters tonull
, and not to the object of type{ name: ``param_${index}``, value: parameter }
.Then in
normalizeParams
indist/typeorm-aurora-data-api.umd.js
:which takes the transformed parameters from above into
params
. It expects each element to be either an array or an object with two or three keys. Whenp
is null,Object.keys(p)
throws the errorTypeError: Cannot convert undefined or null to object
.Because the mysql query transformer
transformParameters
returns null for null parameter values, it breaks innormalizeParams
.Suggested Fix
At src/query-transformer/mysql-query-transformer.ts:127, make the following changes:
The text was updated successfully, but these errors were encountered: