typeorm-aurora-data-api-driver icon indicating copy to clipboard operation
typeorm-aurora-data-api-driver copied to clipboard

AWS Data API (PG) Enum Casting Issue

Open tautologistics opened this issue 3 years ago • 6 comments

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
}

tautologistics avatar May 05 '21 15:05 tautologistics

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

ArsenyYankovsky avatar May 06 '21 15:05 ArsenyYankovsky

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.

tautologistics avatar May 07 '21 02:05 tautologistics

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

seawatts avatar May 25 '21 17:05 seawatts

Any updates on this?

wisaac407 avatar Jul 31 '21 00:07 wisaac407

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

ViniciussSantos avatar May 17 '22 13:05 ViniciussSantos

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.

matias-favale avatar Jul 26 '23 14:07 matias-favale