This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
pluck_to_tstruct
assigns plucked values to the wrong tstruct keys depending on the order in which the tstruct props for associations are listed
#562
Labels
bug
Something isn't working
Describe the bug:
When calling
pluck_to_tstruct
with association mappings, the plucked values do not get assigned to the correct tstruct keys if any of the tstruct props for the associations are listed before the non-association ones.This happens because the associations always end up at the end of the
pluck_keys
array, due to the fact that we have to replace the association keys with their corresponding association values from the association mappings param:sorbet-rails/lib/sorbet-rails/rails_mixins/pluck_to_tstruct.rb
Line 33 in 447ecbe
So when the row of plucked keys gets zipped with
tstruct_keys
, the plucked values do not necessarily get matched up with their corresponding keys, since the association keys intstruct_keys
are in their initial positions rather than at the end of thetstruct_keys
array.sorbet-rails/lib/sorbet-rails/rails_mixins/pluck_to_tstruct.rb
Line 40 in 447ecbe
In addition, this means that if the order of the association keys within the
associations
param topluck_to_tstruct
differs from the order of their corresponding keys in the tstruct class, the plucked association values will also get assigned to the incorrect tstruct keys.Steps to reproduce:
Call
pluck_to_tstruct
with a tstruct class that lists the prop for an association mapping (wand_wood_type
) before any of the non-association ones:The plucked value for
wands.wood_type
gets assigned tohouse
instead ofwand_wood_type
(which also means the pluckedhouse
gets assigned towand_wood_type
)OR
Call
pluck_to_tstruct
with a tstruct class that lists the props for association mappings in a different order than the keys in theassociations
param:It incorrectly tries to assign the plucked value for
wands.core_type
towand_wood_type
, and results in a TypeError:Expected behavior:
All the plucked values get correctly assigned to their corresponding tstruct keys.
Versions:
The text was updated successfully, but these errors were encountered: