tursodatabase / tursodatabase/libsql

Deserialization does not support newtypes

Open
#1,778 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17.2k
Forks
531
Avg merge
1h 12m
Merged PRs (30d)
1

Description

Issue corresponding to a PR #1779. (Relevant tests are included in the PR)
In the current version, newtype fields aren't able to be deserialized as seen below.

#[cfg(feature = "serde")]
#[tokio::test]
async fn deserialize_row() {

// ... ommitted

    #[derive(Deserialize, Debug)]
    struct Data {
        id: i64,
        name: String,
        score: f64,
        data: Vec<u8>,
        age: Option<i64>,
        none: Option<()>,
        status: Status,
        wrapper: Wrapper,
        newtype: NewType,
    }

    #[derive(Deserialize, Debug, PartialEq)]
    struct NewType(String);

// ... ommitted

    let data: Data = libsql::de::from_row(&row).unwrap();

// ... ommitted

    // Fails !!!
    assert_eq!(data.newtype, NewType("Newtype".to_string())); 
}   

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing PR #1779 and its relevant tests, especially the deserialize_row example using libsql:🇩🇪:from_row. Confirm how NewType(String) is handled during deserialization. Done means the provided assertion for data.newtype succeeds and the relevant tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.