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

fields changed to nil #309

Closed
gagalago opened this issue Mar 20, 2017 · 7 comments · Fixed by #315
Closed

fields changed to nil #309

gagalago opened this issue Mar 20, 2017 · 7 comments · Fixed by #315
Assignees
Labels
bug V2 V2 Client

Comments

@gagalago
Copy link

when a save multiple time address of an account, the second time all not updated field are replaced by nil.

This is how to reproduce that

[15] pry(main)> a = Recurly::Account.create(address: { city: "brussels", country: "BE", zip: "1000" }, account_code: "test1")
===> POST https://sortlist-dev.recurly.com/v2/accounts
{"accept"=>["application/xml"], "user-agent"=>["Recurly/2.7.5; ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]"], "x-api-version"=>["2.4"], "accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "authorization"=>["Basic [FILTERED]"], "content-type"=>["application/xml"]}
<account><account_code>test1</account_code><address><city>brussels</city><country>BE</country><zip>1000</zip></address></account>
<=== 201 Created (411.9ms)
{"date"=>["Mon, 20 Mar 2017 08:44:13 GMT"], "content-type"=>["application/xml; charset=utf-8"], "transfer-encoding"=>["chunked"], "connection"=>["keep-alive"], "set-cookie"=>["__cfduid=dc1efe55dbe129db7759c1bb0247e80101489999453; expires=Tue, 20-Mar-18 08:44:13 GMT; path=/; domain=.recurly.com; HttpOnly", "account_credentials=37224d8e20af1f4280a7cb3529851f1e77360ac3e0617161fe1aa86d9707c144a120a0abf7f825623d71729fe76d7c0b325db403b960971ef515f43620b5f932%3A%3A; domain=.recurly.com; path=/", "_recurlyapp_session=5b6f0b682727c6fe887f47173af6b04f; domain=.recurly.com; path=/; secure; HttpOnly"], "x-api-version"=>["2.4"], "content-language"=>["en-US"], "x-ratelimit-limit"=>["2000"], "x-ratelimit-remaining"=>["1992"], "x-ratelimit-reset"=>["1489999740"], "etag"=>["\"dbc3bc18196c4023b67de2d753babd4c\""], "location"=>["https://sortlist-dev.recurly.com/v2/accounts/test1"], "cache-control"=>["max-age=0, private, must-revalidate"], "x-request-id"=>["aqtbhlqscki6rc5j64hg"], "x-ua-compatible"=>["IE=Edge"], "strict-transport-security"=>["max-age=15552000; includeSubDomains; preload"], "server"=>["cloudflare-nginx"], "cf-ray"=>["342763687c724427-BRU"]}
<?xml version="1.0" encoding="UTF-8"?>
<account href="https://sortlist-dev.recurly.com/v2/accounts/test1">
  <adjustments href="https://sortlist-dev.recurly.com/v2/accounts/test1/adjustments"/>
  <account_balance href="https://sortlist-dev.recurly.com/v2/accounts/test1/balance"/>
  <invoices href="https://sortlist-dev.recurly.com/v2/accounts/test1/invoices"/>
  <shipping_addresses href="https://sortlist-dev.recurly.com/v2/accounts/test1/shipping_addresses"/>
  <subscriptions href="https://sortlist-dev.recurly.com/v2/accounts/test1/subscriptions"/>
  <transactions href="https://sortlist-dev.recurly.com/v2/accounts/test1/transactions"/>
  <account_code>test1</account_code>
  <state>active</state>
  <username nil="nil"></username>
  <email nil="nil"></email>
  <cc_emails nil="nil"></cc_emails>
  <first_name nil="nil"></first_name>
  <last_name nil="nil"></last_name>
  <company_name nil="nil"></company_name>
  <vat_number nil="nil"></vat_number>
  <tax_exempt type="boolean">false</tax_exempt>
  <address>
    <address1 nil="nil"></address1>
    <address2 nil="nil"></address2>
    <city>brussels</city>
    <state nil="nil"></state>
    <zip>1000</zip>
    <country>BE</country>
    <phone nil="nil"></phone>
  </address>
  <accept_language nil="nil"></accept_language>
  <hosted_login_token>ed19581624fdf835c26709422469484b</hosted_login_token>
  <created_at type="datetime">2017-03-20T08:44:13Z</created_at>
  <updated_at type="datetime">2017-03-20T08:44:13Z</updated_at>
  <closed_at nil="nil"></closed_at>
  <vat_location_valid type="boolean">false</vat_location_valid>
</account>

=> #<Recurly::Account accept_language: nil, account_code: "test1", address: #<Recurly::Address address1: nil, address2: nil, city: "brussels", country: "BE", phone: nil, state: nil, zip: "1000">, cc_emails: nil, closed_at: nil, company_name: nil, created_at: Mon, 20 Mar 2017 08:44:13 +0000, email: nil, entity_use_code: nil, first_name: nil, hosted_login_token: "ed19581624fdf835c26709422469484b", last_name: nil, state: "active", tax_exempt: false, updated_at: Mon, 20 Mar 2017 08:44:13 +0000, username: nil, vat_location_valid: false, vat_number: nil>
[16] pry(main)> a.address[:address1] = "some street"
=> "some street"
[17] pry(main)> a.save
===> PUT https://sortlist-dev.recurly.com/v2/accounts/test1
{"accept"=>["application/xml"], "user-agent"=>["Recurly/2.7.5; ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]"], "x-api-version"=>["2.4"], "accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "authorization"=>["Basic [FILTERED]"], "content-type"=>["application/xml"]}
<account><account_code>test1</account_code><address><address1>some street</address1></address></account>
<=== 200 OK (671.8ms)
{"date"=>["Mon, 20 Mar 2017 08:44:29 GMT"], "content-type"=>["application/xml; charset=utf-8"], "transfer-encoding"=>["chunked"], "connection"=>["keep-alive"], "set-cookie"=>["__cfduid=d0880d68302dd427780f9748438b467ae1489999469; expires=Tue, 20-Mar-18 08:44:29 GMT; path=/; domain=.recurly.com; HttpOnly"], "vary"=>["Accept-Encoding"], "x-api-version"=>["2.4"], "content-language"=>["en-US"], "x-ratelimit-limit"=>["2000"], "x-ratelimit-remaining"=>["1991"], "x-ratelimit-reset"=>["1489999740"], "etag"=>["W/\"5e007aa020d55f43d733dc958c29b1a8\""], "location"=>["https://sortlist-dev.recurly.com/v2/accounts/test1"], "cache-control"=>["max-age=0, private, must-revalidate"], "x-request-id"=>["aqtbhpodjqb4ro9tp4gg"], "x-ua-compatible"=>["IE=Edge"], "strict-transport-security"=>["max-age=15552000; includeSubDomains; preload"], "server"=>["cloudflare-nginx"], "cf-ray"=>["342763cb5f65444b-BRU"]}
<?xml version="1.0" encoding="UTF-8"?>
<account href="https://sortlist-dev.recurly.com/v2/accounts/test1">
  <adjustments href="https://sortlist-dev.recurly.com/v2/accounts/test1/adjustments"/>
  <account_balance href="https://sortlist-dev.recurly.com/v2/accounts/test1/balance"/>
  <invoices href="https://sortlist-dev.recurly.com/v2/accounts/test1/invoices"/>
  <shipping_addresses href="https://sortlist-dev.recurly.com/v2/accounts/test1/shipping_addresses"/>
  <subscriptions href="https://sortlist-dev.recurly.com/v2/accounts/test1/subscriptions"/>
  <transactions href="https://sortlist-dev.recurly.com/v2/accounts/test1/transactions"/>
  <account_code>test1</account_code>
  <state>active</state>
  <username nil="nil"></username>
  <email nil="nil"></email>
  <cc_emails nil="nil"></cc_emails>
  <first_name nil="nil"></first_name>
  <last_name nil="nil"></last_name>
  <company_name nil="nil"></company_name>
  <vat_number nil="nil"></vat_number>
  <tax_exempt type="boolean">false</tax_exempt>
  <address>
    <address1>some street</address1>
    <address2 nil="nil"></address2>
    <city nil="nil"></city>
    <state nil="nil"></state>
    <zip nil="nil"></zip>
    <country nil="nil"></country>
    <phone nil="nil"></phone>
  </address>
  <accept_language nil="nil"></accept_language>
  <hosted_login_token>ed19581624fdf835c26709422469484b</hosted_login_token>
  <created_at type="datetime">2017-03-20T08:44:13Z</created_at>
  <updated_at type="datetime">2017-03-20T08:44:29Z</updated_at>
  <closed_at nil="nil"></closed_at>
  <vat_location_valid nil="nil"></vat_location_valid>
</account>

=> true

As we can see in this example, at the end, only the address1 is in the address and city, country, zip disapear.

ps: maybe the problem apear on others fields or api endpoints

@bhelx bhelx self-assigned this Mar 20, 2017
@bhelx
Copy link
Contributor

bhelx commented Mar 20, 2017

@gagalago It looks to me like maybe the Address needs every field sent when doing an update. I'll confirm and see if I can get a fix out quick.

@bhelx bhelx added the bug? label Mar 20, 2017
@gagalago
Copy link
Author

yes, I can confirm that the address need all fields but this gem send only changed fields of a Resource object, so I have to recreate a new hash to have all fields dirty.

irb(main):001:0> a = Recurly::Account.find "test1"
===> GET https://sortlist-dev.recurly.com/v2/accounts/test1
===> GET https://sortlist-dev.recurly.com/v2/accounts/test1
{"accept"=>["application/xml"], "user-agent"=>["Recurly/2.7.5; ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]"], "x-api-version"=>["2.4"], "accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "authorization"=>["Basic [FILTERED]"]}
<=== 200 OK (412.2ms)
<=== 200 OK (412.2ms)
{"date"=>["Tue, 21 Mar 2017 08:11:36 GMT"], "content-type"=>["application/xml; charset=utf-8"], "transfer-encoding"=>["chunked"], "connection"=>["keep-alive"], "set-cookie"=>["__cfduid=d0103495358884cf34d153ddb1440bd7b1490083896; expires=Wed, 21-Mar-18 08:11:36 GMT; path=/; domain=.recurly.com; HttpOnly"], "vary"=>["Accept-Encoding"], "x-api-version"=>["2.4"], "content-language"=>["en-US"], "x-ratelimit-limit"=>["2000"], "x-ratelimit-remaining"=>["1999"], "x-ratelimit-reset"=>["1490084160"], "etag"=>["W/\"1a7d820f0ae929fe1236257cac317a7f\""], "last-modified"=>["Mon, 20 Mar 2017 08:47:23 GMT"], "cache-control"=>["max-age=0, private, must-revalidate"], "x-request-id"=>["aqtvltp2pg4jmsntuh6g"], "x-ua-compatible"=>["IE=Edge"], "strict-transport-security"=>["max-age=15552000; includeSubDomains; preload"], "server"=>["cloudflare-nginx"], "cf-ray"=>["342f70ff9fff23fc-IAD"]}
<?xml version="1.0" encoding="UTF-8"?>
<account href="https://sortlist-dev.recurly.com/v2/accounts/test1">
  <adjustments href="https://sortlist-dev.recurly.com/v2/accounts/test1/adjustments"/>
  <account_balance href="https://sortlist-dev.recurly.com/v2/accounts/test1/balance"/>
  <invoices href="https://sortlist-dev.recurly.com/v2/accounts/test1/invoices"/>
  <shipping_addresses href="https://sortlist-dev.recurly.com/v2/accounts/test1/shipping_addresses"/>
  <subscriptions href="https://sortlist-dev.recurly.com/v2/accounts/test1/subscriptions"/>
  <transactions href="https://sortlist-dev.recurly.com/v2/accounts/test1/transactions"/>
  <account_code>test1</account_code>
  <state>active</state>
  <username nil="nil"></username>
  <email nil="nil"></email>
  <cc_emails nil="nil"></cc_emails>
  <first_name nil="nil"></first_name>
  <last_name nil="nil"></last_name>
  <company_name nil="nil"></company_name>
  <vat_number nil="nil"></vat_number>
  <tax_exempt type="boolean">false</tax_exempt>
  <address>
    <address1>some street</address1>
    <address2 nil="nil"></address2>
    <city>brussels</city>
    <state nil="nil"></state>
    <zip>1000</zip>
    <country>BE</country>
    <phone nil="nil"></phone>
  </address>
  <accept_language nil="nil"></accept_language>
  <hosted_login_token>ed19581624fdf835c26709422469484b</hosted_login_token>
  <created_at type="datetime">2017-03-20T08:44:13Z</created_at>
  <updated_at type="datetime">2017-03-20T08:47:23Z</updated_at>
  <closed_at nil="nil"></closed_at>
  <vat_location_valid type="boolean">false</vat_location_valid>
</account>

=> #<Recurly::Account accept_language: nil, account_code: "test1", address: #<Recurly::Address address1: "some street", address2: nil, city: "brussels", country: "BE", phone: nil, state: nil, zip: "1000">, cc_emails: nil, closed_at: nil, company_name: nil, created_at: Mon, 20 Mar 2017 08:44:13 +0000, email: nil, entity_use_code: nil, first_name: nil, hosted_login_token: "ed19581624fdf835c26709422469484b", last_name: nil, state: "active", tax_exempt: false, updated_at: Mon, 20 Mar 2017 08:47:23 +0000, username: nil, vat_location_valid: false, vat_number: nil>
irb(main):004:0> a.address = { city: "brussels", country: "BE", zip: "1000", address1: "some street" }
=> {:city=>"brussels", :country=>"BE", :zip=>"1000", :address1=>"some street"}
irb(main):005:0> a.save
===> PUT https://sortlist-dev.recurly.com/v2/accounts/test1
===> PUT https://sortlist-dev.recurly.com/v2/accounts/test1
{"accept"=>["application/xml"], "user-agent"=>["Recurly/2.7.5; ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]"], "x-api-version"=>["2.4"], "accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], "authorization"=>["Basic [FILTERED]"], "content-type"=>["application/xml"]}
<account><account_code>test1</account_code><address><city>brussels</city><country>BE</country><zip>1000</zip><address1>some street</address1></address></account>
<=== 200 OK (562.4ms)
<=== 200 OK (562.4ms)
{"date"=>["Tue, 21 Mar 2017 08:26:22 GMT"], "content-type"=>["application/xml; charset=utf-8"], "transfer-encoding"=>["chunked"], "connection"=>["keep-alive"], "set-cookie"=>["__cfduid=d94f076294f7c3be060fd2239596499ae1490084782; expires=Wed, 21-Mar-18 08:26:22 GMT; path=/; domain=.recurly.com; HttpOnly"], "vary"=>["Accept-Encoding"], "x-api-version"=>["2.4"], "content-language"=>["en-US"], "x-ratelimit-limit"=>["2000"], "x-ratelimit-remaining"=>["1998"], "x-ratelimit-reset"=>["1490085060"], "etag"=>["W/\"05202773e270e15e2e82548bbe4de31d\""], "location"=>["https://sortlist-dev.recurly.com/v2/accounts/test1"], "cache-control"=>["max-age=0, private, must-revalidate"], "x-request-id"=>["aqtvsm47eqifll5sv6t0"], "x-ua-compatible"=>["IE=Edge"], "strict-transport-security"=>["max-age=15552000; includeSubDomains; preload"], "server"=>["cloudflare-nginx"], "cf-ray"=>["342f86a23e635759-IAD"]}
<?xml version="1.0" encoding="UTF-8"?>
<account href="https://sortlist-dev.recurly.com/v2/accounts/test1">
  <adjustments href="https://sortlist-dev.recurly.com/v2/accounts/test1/adjustments"/>
  <account_balance href="https://sortlist-dev.recurly.com/v2/accounts/test1/balance"/>
  <invoices href="https://sortlist-dev.recurly.com/v2/accounts/test1/invoices"/>
  <shipping_addresses href="https://sortlist-dev.recurly.com/v2/accounts/test1/shipping_addresses"/>
  <subscriptions href="https://sortlist-dev.recurly.com/v2/accounts/test1/subscriptions"/>
  <transactions href="https://sortlist-dev.recurly.com/v2/accounts/test1/transactions"/>
  <account_code>test1</account_code>
  <state>active</state>
  <username nil="nil"></username>
  <email nil="nil"></email>
  <cc_emails nil="nil"></cc_emails>
  <first_name nil="nil"></first_name>
  <last_name nil="nil"></last_name>
  <company_name nil="nil"></company_name>
  <vat_number nil="nil"></vat_number>
  <tax_exempt type="boolean">false</tax_exempt>
  <address>
    <address1>some street</address1>
    <address2 nil="nil"></address2>
    <city>brussels</city>
    <state nil="nil"></state>
    <zip>1000</zip>
    <country>BE</country>
    <phone nil="nil"></phone>
  </address>
  <accept_language nil="nil"></accept_language>
  <hosted_login_token>ed19581624fdf835c26709422469484b</hosted_login_token>
  <created_at type="datetime">2017-03-20T08:44:13Z</created_at>
  <updated_at type="datetime">2017-03-21T08:26:22Z</updated_at>
  <closed_at nil="nil"></closed_at>
  <vat_location_valid type="boolean">false</vat_location_valid>
</account>

=> true

@bhelx
Copy link
Contributor

bhelx commented Mar 22, 2017

@gagalago This is in fact a bug. Would you mind trying #315 and seeing if that fixes it for you? I'm going to add specs for it now.

@bhelx
Copy link
Contributor

bhelx commented Mar 22, 2017

@gagalago Also I believe this is something that is unique to the Address object.

@gagalago
Copy link
Author

yes thanks, it fix it

@bhelx
Copy link
Contributor

bhelx commented Mar 30, 2017

@gagalago Okay, I've got to get the tests working on that branch then we can push a release.

@bhelx
Copy link
Contributor

bhelx commented Apr 6, 2017

For anyone following, this is now out in release 2.9.0: https://github.com/recurly/recurly-client-ruby/releases/tag/2.9.0

@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 V2 Client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants