sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Regression in v0.6 when decoding an PostgreSQL enum in a PgRecordDecoder

Open Thomasdezeeuw opened this issue 3 years ago • 8 comments

I don't have a complete reproduction at the moment although I could work on it.

The basic issue is that we're using a custom PostgreSQL enum, i.e. CREATE TYPE MyEnum AS ENUM ( ... ), and try to decode that from a PgRecordDecoder using try_decode. On the rust side the enum derives sqlx::Type nothing else special. In v0.5 this works fine, but in v0.6 it hits the following error:

error occurred while decoding column variables: custom types in records are not fully supported yet: failed to retrieve type info for field 4 with type oid 25101253

Where oid 25101253 is our enum. The error comes from: https://github.com/launchbadge/sqlx/blob/8fd7ee72a62449af592bf3c43d360a3d64f6195c/sqlx-core/src/postgres/types/record.rs#L136 Which was added in https://github.com/launchbadge/sqlx/pull/1855 (hence my comment there).

Thomasdezeeuw avatar Jun 21 '22 09:06 Thomasdezeeuw

I just tried partially reverting #1855 with the following patch and that fixes the issue. Would that be an acceptable change?

diff --git a/sqlx-core/src/postgres/types/record.rs b/sqlx-core/src/postgres/types/record.rs
index 352bdb72..c2b1bcce 100644
--- a/sqlx-core/src/postgres/types/record.rs
+++ b/sqlx-core/src/postgres/types/record.rs
@@ -132,8 +132,7 @@ impl<'r> PgRecordDecoder<'r> {
                 }
 
                 let element_type =
-                    element_type_opt
-                        .ok_or_else(|| BoxDynError::from(format!("custom types in records are not fully supported yet: failed to retrieve type info for field {} with type oid {}", self.ind, element_type_oid.0)))?;
+                    element_type_opt.unwrap_or_else(|| PgTypeInfo::with_oid(element_type_oid));
 
                 self.ind += 1;
 

Thomasdezeeuw avatar Jun 21 '22 09:06 Thomasdezeeuw

Unfortunately, I think that's just going to bring back the panic in the array decode case, which you yourself reported in #1672.

abonander avatar Jun 22 '22 07:06 abonander

@abonander that's unfortunate, but it's still a clear regression. Is there a middle road we can take? Maybe delay the creation of the error to the point where it previously panicked? This way at least the custom enum within a record will keep working.

Thomasdezeeuw avatar Jun 22 '22 08:06 Thomasdezeeuw

Thank you for reporting this error. I was busy for a few weeks but still intend to refactor SQLx to fully support custom types. I am sorry for the regression.

I'll try to look into this in the next days.

demurgos avatar Jul 06 '22 20:07 demurgos

@demurgos any update on this? I could look into this myself if you don't have the time.

Thomasdezeeuw avatar Jul 18 '22 09:07 Thomasdezeeuw

This is still preventing us from updating, any news?

Thomasdezeeuw avatar Sep 02 '22 15:09 Thomasdezeeuw

This is still preventing us from updating, any news?

Me too— is this issue planned for 0.7?

Iron-E avatar Apr 17 '23 18:04 Iron-E

+1, having the same issue. any resolution here?

maxwolff avatar Jan 30 '24 22:01 maxwolff