Skip to content

Relationships and attributes property collision  #27

Open
@leoamigood

Description

@leoamigood

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions