Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

PostgreSQL - Could not convert value to IpAddr #416

Open
carlos-rian opened this issue Oct 27, 2022 · 1 comment
Open

PostgreSQL - Could not convert value to IpAddr #416

carlos-rian opened this issue Oct 27, 2022 · 1 comment

Comments

@carlos-rian
Copy link

carlos-rian commented Oct 27, 2022

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 carlos-rian changed the title Could not convert value from CIDR type to IpAddr - PostgreSQL Could not convert value to IpAddr - PostgreSQL Oct 27, 2022
@Simponic
Copy link

Simponic commented Nov 22, 2022

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?

PostgresType::INET | PostgresType::CIDR => match row.try_get(i)? {
Some(val) => {
let val: std::net::IpAddr = val;
Value::text(val.to_string())
}
None => Value::Text(None),

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.

@carlos-rian carlos-rian changed the title Could not convert value to IpAddr - PostgreSQL PostgreSQL - Could not convert value to IpAddr Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants