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

AWS Data API (PG) Enum Casting Issue #80

Open
tautologistics opened this issue May 5, 2021 · 6 comments
Open

AWS Data API (PG) Enum Casting Issue #80

tautologistics opened this issue May 5, 2021 · 6 comments

Comments

@tautologistics
Copy link

tautologistics commented May 5, 2021

Package versions and database engine type (please complete the following information):

  • Database Engine: postgres
  • TypeORM Version: 0.2.32
  • Driver Version: 2.1.0

Describe the bug
Entities that have enum column types cause errors when trying to query the database where the enum column is in the WHERE criteria. The error is caused because the enum column criteria value is not cast correctly.

To Reproduce
https://github.com/veho-technologies/typeorm-data-api-enum-issue

The above repo describes and demonstrates the issue.

Example error:

BadRequestException: ERROR: operator does not exist: example_status_enum = character varying
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 313
    at Object.extractError (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/protocol/json.js:52:27)
    at Request.extractError (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)
    at Request.callListeners (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/chris/projects/veho/seshat-debug/node_modules/aws-sdk/lib/request.js:690:12) {
  code: 'BadRequestException',
  time: 2021-05-05T15:46:47.936Z,
  requestId: 'xxXxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
  statusCode: 400,
  retryable: false,
  retryDelay: 78.57561114326721
}
@ArsenyYankovsky
Copy link
Owner

We currently cannot automatically cast parameters. Please try to use explicit casting as described here

@tautologistics
Copy link
Author

Thank you! Completely missed the explicit cast ability in the docs.

This solves my immediately problem but it is worth noting for whomever else runs into this, that the explicit casting doesn't seem to work when using TypeORM's In().

Regardless, thanks for all the effort you've put into this driver; it is very much appreciated.

@seawatts
Copy link
Contributor

I'm still seeing this issue as well with the new auto casting

@wisaac407
Copy link

Any updates on this?

@ViniciussSantos
Copy link

I'm still having this problem, any updates or workarounds ?

@matias-favale
Copy link

matias-favale commented Jul 26, 2023

2023, this is still an issue for SIMPLE enum casting. I had to change my query from this:

enum EnumExample {
    VALUE = "VALUE"
}

.where({ column: EnumExample.VALUE })

to this:

.where(`column = '${EnumExample.VALUE}'`)

why is this such a big deal to resolve? I really don't get it.

Note: The solution provided for explicit casting does not show any example for enum type casting, only for jsonb or uuid, it is not clear also what is doing behind the scenes or where that can be used and also clients of a driver shouldn't have to do stuff differently because the driver requires it. Drivers have to have a common contract that respects, otherwise the client cannot switch drivers, which is the whole purpose of using drivers in the first place.

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

No branches or pull requests

6 participants