Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] deep_merge does not work on HashWithIndifferentAccess

#2732

When I have 2 hashes (HashWithIndifferntAccess) and do deep_merge, it seems that it do not merge.

(rdb:1) params {"submit"=>"Where", "action"=>"query", "controller"=>"locations", "query"=>{"text"=>"50,14"}} (rdb:1) params_new {:query=>{:type=>"coordinates"}, :location=>{:geo_attributes=>{:coordinates=>"50.0,14.0"}}}

(rdb:1) params_after_deep_merge {"submit"=>"Where", "action"=>"query", "controller"=>"locations", "query"=>{"type"=>"coordinates"}, "location"=>{"geo_attributes"=>{"coordinates"=>"50.0,14.0"}}}

(missing "query" => {"text" ...})

When both hashes are regular Hashes (not WithIndifferentAccess), they merge ok.

{"submit"=>"Where", "action"=>"query", "controller"=>"locations", "query"=>{"type"=>"coordinates", "text"=>"50,14"}, "location"=>{"geo_attributes"=>{"coordinates"=>"50.0,14.0"}}}

Rails 2.3.2, OS X

It seems that in
File vendor/rails/activesupport/lib/active_support/core_ext/hash/deep_merge.rb

line11:
oldval.class.to_s == 'Hash' && newval.class.to_s == 'Hash' ? oldval.deep_merge(newval) : newval

should be something like:

oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval

Reported by david.cizek (at gmail) · May 28th, 2009 @ 10:29 AM

State: stale
Milestone: 2.3.10
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. david.cizek (at gmail)
    david.cizek (at gmail)

    My last "should be something..." was stupid, I did not mentioned?! 2 lines before, sorry. But still... does not work.

    I tried to document the behaviour little bit more on:
    http://gist.github.com/119217

    David

    May 28th, 2009 @ 11:45 AM

  2. CancelProfileIsBroken
  3. Derander
    Derander
    • Tag changed from bugmash to bugmash, patch

    +1 verified.

    I packaged the (slightly tweaked) above methods into a patch with failing tests.

    The patch should apply against 2-3-stable.

    August 9th, 2009 @ 04:58 AM

  4. Derander
    Derander
    • Title changed from deep_merge does not work on HashWithIndifferentAccess to [PATCH] deep_merge does not work on HashWithIndifferentAccess

    August 9th, 2009 @ 04:59 AM

  5. Rizwan Reza
    Rizwan Reza
    • Tag changed from bugmash, patch to 2.3.x, bugmash, patch, verified

    verified

    +1 The patch applies cleanly under 2-3-stable only.

    August 9th, 2009 @ 05:06 AM

  6. Kieran P
    Kieran P
    • Tag changed from 2.3.x, bugmash, patch, verified to bugmash, patch

    +1 Verified, and patch applies to 2-3 cleanly and fixes included test.

    Also ported to master. Attaching patch now.

    August 9th, 2009 @ 05:14 AM

  7. Jeremy Kemper
    Jeremy Kemper

    Kieran, when you apply commits from 2-3-stable to master (or vice versa), use git cherry-pick <revision> to retain the original authorship and commit message.

    August 9th, 2009 @ 09:56 PM

  8. Derander
    Derander

    Here is my patch applied for master.

    August 9th, 2009 @ 11:03 PM

  9. Rizwan Reza
    Rizwan Reza

    verified

    +1 The patch applies cleanly and all tests pass.

    August 9th, 2009 @ 11:12 PM

  10. José Valim
    José Valim

    We cannot put Rails current deep_merge into a module and add the module to both Hash and ActiveSupport::HashWithIndifferentAccess?

    August 9th, 2009 @ 11:15 PM

  11. Jeremy Kemper
    Jeremy Kemper

    Good call. A mixin is best here.

    August 9th, 2009 @ 11:18 PM

  12. Derander
    Derander

    I don't think a mixin is needed because HashWithIndiff inherits from Hash.

    Anyways, here is an alternate implementation of the above patch where it replaces Hash's deep_merge method

    Tests all pass on master

    August 9th, 2009 @ 11:41 PM

  13. Rizwan Reza
    Rizwan Reza

    verified

    +1 This patch applies cleanly.

    August 9th, 2009 @ 11:43 PM

  14. Tristan Dunn
    Tristan Dunn

    +1

    Verified Derander's patch applies cleanly to master and tests are passing.

    August 9th, 2009 @ 11:49 PM

  15. Repository
    Repository
    • State changed from new to committed

    (from [ca92d44e7637ae6d28d6b88b67873d2795290cb5]) Support deep-merging HashWithIndifferentAccess.

    [#2732 state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
    http://github.com/rails/rails/commit/ca92d44e7637ae6d28d6b88b67873d...

    August 10th, 2009 @ 01:34 AM

  16. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from bugmash, patch to patch
    • Milestone cleared.

    August 10th, 2009 @ 02:14 AM

  17. Santiago Pastorino
    Santiago Pastorino
    • Milestone set to 2.3.9
    • Assigned user set to Jeremy Kemper

    June 1st, 2010 @ 09:47 AM

  18. Santiago Pastorino
    Santiago Pastorino
    • State changed from committed to open

    June 1st, 2010 @ 09:48 AM

  19. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.9 to 2.3.10
    • Importance changed from to

    August 30th, 2010 @ 02:28 AM

  20. Santiago Pastorino
    Santiago Pastorino

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:32 PM

  21. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:32 PM