Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

duckies
Copy link
Contributor

@duckies duckies commented Jan 1, 2020

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.

  • Functionality testing using arrays.
  • Functionality testing without arrays.

@duckies duckies changed the title Patch enum of strings spaces in Postgres. Fix: Enums with spaces are not converted properly Jan 1, 2020
Signed-off-by: duckies <gilbert.johnt@gmail.com>
@RobertWHurst
Copy link

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);
Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seconding this.

@javierlinked
Copy link

We are facing the same issue. And waiting this fix to be included into main branch. Thanks.

Copy link
Contributor

@imnotjames imnotjames left a 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";
Copy link
Contributor

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}"],
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seconding this.

@duckies
Copy link
Contributor Author

duckies commented Oct 16, 2020

I personally no longer use TypeORM, so if a more generalized solution is desired feel free to close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants