typeorm-aurora-data-api-driver
typeorm-aurora-data-api-driver copied to clipboard
AWS Data API (PG) Enum Casting Issue
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
}
We currently cannot automatically cast parameters. Please try to use explicit casting as described here
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.
I'm still seeing this issue as well with the new auto casting
Any updates on this?
I'm still having this problem, any updates or workarounds ?
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.