Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshal error ignored #209

Open
jkoelker opened this issue Oct 8, 2021 · 5 comments
Open

Unmarshal error ignored #209

jkoelker opened this issue Oct 8, 2021 · 5 comments

Comments

@jkoelker
Copy link

jkoelker commented Oct 8, 2021

Several of the generated models have a bug in them where an empty model will be returned with no error when there is an error unmarshaling them.

A simple repro case:

package main

import (
        "fmt"
        "encoding/json"

        "github.com/plaid/plaid-go/plaid"
)

func main() {
        acct := plaid.AccountBase{
                AccountId: "test id",
        }

        data, err := json.Marshal(acct)
        if err != nil {
                fmt.Println(err.Error())
                return
        }

        account := plaid.AccountBase{}
        err = json.Unmarshal(data, &account)
        if err != nil {
                fmt.Println(err.Error())
                return
        }

        fmt.Printf("%v\n", acct)
        fmt.Printf("%s\n", data)
        fmt.Printf("%v\n", account)
}

Since AccountBase contains a Type that is an enum there is an error unmarshaling an empty string, but that error is ignored and the additional properties are decoded, and its error is returned instead.

This is a bug in the generator templates it appears to the handled correctly when isMap is true.

@stephenjayakar
Copy link
Contributor

What version of the go client library are you using? I tried using v1.6.0 and here's my output (don't see any error)

{test id {{<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} map[]} {<nil> false}  {<nil> false}  {<nil> false} <nil> map[]}
{"account_id":"test id","balances":{"available":null,"current":null,"iso_currency_code":null,"limit":null,"unofficial_currency_code":null},"mask":null,"name":"","official_name":null,"subtype":null,"type":""}
{ {{<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} map[]} {<nil> false}  {<nil> false}  {<nil> false} <nil> map[]}

@jkoelker
Copy link
Author

jkoelker commented Oct 29, 2021

What version of the go client library are you using? I tried using v1.6.0 and here's my output (don't see any error)

{test id {{<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} map[]} {<nil> false}  {<nil> false}  {<nil> false} <nil> map[]}
{"account_id":"test id","balances":{"available":null,"current":null,"iso_currency_code":null,"limit":null,"unofficial_currency_code":null},"mask":null,"name":"","official_name":null,"subtype":null,"type":""}
{ {{<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} {<nil> false} map[]} {<nil> false}  {<nil> false}  {<nil> false} <nil> map[]}

Correct there IS no error and it should be. The last line you have there is the account notice how it does not have the AccountId field, what is happening is the json.Unmarshal at https://github.com/plaid/plaid-go/blob/master/plaid/model_account_base.go#L304 is failing and returning an error. The if guard there, checks if there was not an error unmarshaling, and if there wasn't it sets the pointer's value to a copy of the unmarshaled object, then continues on with the additional properties, never informing the calling code that the initial error happened, and that the if guard is leaving the object empty.

You'll see if you add in other properties that are not being deleted explicitly by the unserializer, that all the properties are being stuffed in the additional properties.

@jkoelker
Copy link
Author

jkoelker commented Oct 29, 2021

I would also like to re-iterate this is not just a bug in this AccountBase model, but every model that contains additional properties and a custom deserializer for subtypes.

@ajorgensen
Copy link

ajorgensen commented Nov 17, 2023

I just ran into this as well. It seems that the addition of a new product strings for Institutions is enough to cause the sdk to return an zero response object and no error. I ran into this when querying for Institutions by ID in the sandbox which returned a product that was not present in the local version of the sdk that I was using. I can craft a test case to show the issue if that is helpful but it took quite a while to debug why the sdk was returning a zero object and no error.

@phoenixy1
Copy link

FYI @cgfarmer4 and @aarohmankad perhaps something to look at for next month? (This one is a bit out of my depth to fix.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants