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

Relationships and attributes property collision #27

Open
leoamigood opened this issue Sep 26, 2023 · 0 comments
Open

Relationships and attributes property collision #27

leoamigood opened this issue Sep 26, 2023 · 0 comments

Comments

@leoamigood
Copy link

There is an issue in case payload deserialization like this happens:

{
   "data":{
      "type":"billing_period",
      "attributes":{
         "invoiceType":"prepayment",
         "billingPeriodStart":"2022-06-01",
         "billingPeriodEnd":"2022-07-01",
         "amount":"2000"
      },
      "relationships":{
         "invoice":{
            "data":{
               "type":"invoice",
               "id":"42b2a67b-5c50-4d8f-b91e-e4269933b007"
            }
         }
      }
   }
}

In this case due to hash merging order relationships always take precedence over attributes,
so the deserialized attribute invoiceType in the case above will be invoice instead of expected prepayment.

The fix may be as easy as switching the order for deserialize_rels and deserialize_attrs

        hashes = [deserialize_type, deserialize_id,
                  deserialize_rels, deserialize_attrs]

though it's not backwards compatible.

Please suggest,
Leo

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

1 participant