vapor / fluent-postgres-driver

🐘 PostgreSQL driver for Fluent.
MIT License
146 stars 53 forks source link

Saving optional enum (nil) triggers: [ WARNING ] bind $3 type (UNKNOWN 0) does not match expected parameter type (TEXT) #149

Closed finestructure closed 4 years ago

finestructure commented 4 years ago

As discussed here: https://discordapp.com/channels/431917998102675485/684159753189982218/704938144323076136

When inserting nil for an optional enum:

enum Status: String, Codable {
  case ok
  ...
}

...

    @Enum(key: "status")
    var status: Status?

...

I observe the following message in the console:

[ WARNING ] bind $3 type (UNKNOWN 0) does not match expected parameter type (TEXT)

There seems to be no adverse effect and saving non-nil enum works fine.

tanner0101 commented 4 years ago

@finestructure can you try using @OptionalEnum instead of @Enum? I'm a bit surprised @Enum is working there actually.

finestructure commented 4 years ago

Sure! I’ll give that a go and report back.

tanner0101 commented 4 years ago

Hmm yeah I'm getting this error when I try to use @Enum.

Cannot convert value of type 'EnumProperty<Foo, _>' to specified type 'Status?'

Only @OptionalEnum works for me and I'm not able to recreate the warning there.

finestructure commented 4 years ago

I'll try and create a test case in the project but it'll take moment because I've now moved on to using @Enum and var status: Status with a default case none instead of optional.

finestructure commented 4 years ago

FYI: I've just tried with @OptionalEnum and it works fine. I also can't reproduce the original error anymore. Not sure if it was an update in the meantime that fixed it or if something else changed 🤷

I'll close this now - thanks for taking a look! :)