-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Fix: Enums with spaces are not converted properly #5276
Conversation
Signed-off-by: duckies <gilbert.johnt@gmail.com>
My team just ran into this issue. It's a pretty crucial bug, would be really nice to see this fixed. Our product does hotel bookings, and this caused some serious issues for us. |
// Remove extraneous delimiting quotes around enum strings with spaces. | ||
value = value.map((val: string) => { | ||
// Returns an empty string if the length is negative. | ||
const stripped = val.substr(1, val.length - 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code isn't obvious to me. As I understood you are trying to remove quotes around enum strings by this code. But what if there are no quotes around? Wouldn't it remove regular characters from it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding this.
We are facing the same issue. And waiting this fix to be included into main branch. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be changed to make it more general? Does this issue apply to other drivers as well or only Postgres? What about cockroach?
@@ -0,0 +1,44 @@ | |||
import "reflect-metadata"; | |||
import { Connection } from "../../../src"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire test file needs to be in the correct directory
describe("github issues > #5275 Enums with spaces are not converted properly.", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass the entities in directly
// Remove extraneous delimiting quotes around enum strings with spaces. | ||
value = value.map((val: string) => { | ||
// Returns an empty string if the length is negative. | ||
const stripped = val.substr(1, val.length - 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seconding this.
I personally no longer use TypeORM, so if a more generalized solution is desired feel free to close this. |
Postgres returns values for enum arrays in formats like
{"Guild Master", Recruit}
and are incorrectly converted to['"Guild Master"', 'Recruit' ]
.Potential issues arise depending on the fix implementation if the user wanted quotes in their enum. I utilized a dirty patch that removes the first and last characters from the string and determines if it's a valid enum.