quaint icon indicating copy to clipboard operation
quaint copied to clipboard

PostgreSQL - Could not convert value to IpAddr

Open carlos-rian opened this issue 2 years ago • 1 comments

Description

I ran a query_raw where the PostgreSQL column is of type CIDR or MacAddr but I got this error.

This message is in the src/ast/values.rs file, line 788.

Value in column: 192.168.100.128/25 and 08:00:2b:01:02:03

Error

CIDR Error querying the database: error deserializing column 24: cannot convert between the Rust type core::option::Option<std::net::ip::IpAddr> and the Postgres type cidr

MacAddr has the same problem Column type 'macaddr' could not be deserialized from the database.

carlos-rian avatar Oct 27 '22 20:10 carlos-rian

I'm also running into these issues trying to create the following models:

model Network {
  id                       Int    @id @default(autoincrement())
  subnet                   String @unique @db.Inet

  @@index([subnet(ops: InetOps)], type: Gist)
}

model AP {
  id            Int                    @id @default(autoincrement())
  macAddr       Unsupported("macaddr")
}

Now, I know absolutely nothing about Rust, but from the given error I found https://doc.rust-lang.org/std/net/struct.AddrParseError.html which led me on a hunt. Could it be from attempting to parse it with std::net::IpAddr, which does not support subnets? https://github.com/prisma/quaint/blob/657a56a38f6d61533ecbc71935eff61fbcf6af54/src/connector/postgres/conversion.rs#L489-L494

I'm sorry in advance if this is completely wrong, just trying to add some traffic onto this issue with my very limited knowledge since this fix is important to me.

Simponic avatar Nov 22 '22 20:11 Simponic