ynab / ynab-sdk-ruby

YNAB API Client for Ruby
https://api.ynab.com
Apache License 2.0
65 stars 12 forks source link

Validation error on API response for `TransactionDetail#import_payee_name` #65

Closed davidstosik closed 1 year ago

davidstosik commented 1 year ago

Hi there! 👋🏻

The YNAB API is working very well and I'm thankful this gem is available, making it super easy to write scripts to import transactions.

However, I am experiencing an error which to me looks weird and unjustified. I'm not sure whether this is a bug, but I thought I'd report what I'm seeing and ask for opinions.

I have a script which goal is to create YNAB transactions in my account, based on local CSV data. It initializes a YNAB::PostTransactionsWrapper in which the transactions keyword argument is an Array of Hashes with the necessary transaction keys/properties.

The script then uses the TransactionsApi's #create_transaction method to send the data to YNAB, which usually goes well.

Sometimes though, that calls raises an exception:

#<ArgumentError: invalid value for "import_payee_name", the character length must be smaller than or equal to 200.>

I can verify on my YNAB account that all the transactions were created correctly, so my guess is that the error is raised after the gem received a successful response from the API.

It looks like the gem attempts to deserialize the response into a SaveTransactionResponse, which is supposed to include each created transaction, deserialized as a TransactionDetail. Unfortunately, it seems that the deserialization fails when the import_payee_name validation fails:

https://github.com/ynab/ynab-sdk-ruby/blob/f14a86668e3d216aef94fbc2ee202a96d9bcb979/lib/ynab/models/transaction_detail.rb#L280-L282

I don't recall ever importing data with 200+ character long payee names, but even if I did, I think there is a consistency problem between the gem and the API:

The error does not really impact my process: the transactions I want to create get created with no issue, and I'm currently not making any use of the response, but I think this is a smell that might be worth fixing.

Please let me know if I can help in any way.

(@bradymholt It looks like you've been maintaining this gem for a while, so please allow me to ping you in the issue. 🙇🏻‍♂️ )

bradymholt commented 1 year ago

Thanks for the detailed report @davidstosik! This should be fixed in v1.29.0.

davidstosik commented 1 year ago

@bradymholt Thank you very much!