active-hash / active-hash/active_hash

Instance Variables and Re-used Objects

Open
#124 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v2.0.0
Dominant language
Ruby
Stars
1.4k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

I run into some trouble with ActiveHash when I set some per-request data on instance variables of an ActiveHash instance. I expected the ActiveHash finder methods to return fresh objects the way ActiveRecord does when you call find or where().first or whatnot.

I wrote a patch that separates the original state of the records in an ActiveHash sub-class from the records that are being passed around in the rest of the application. There is a bit of memory overhead to passing cloned objects instead of references to the same object, but that is true for ActiveRecord as well and it does not gum things up too much. I will submit a PR so you guys can have a look.

Alternatively to cloning objects, ActiveHash could freeze the records so they raise errors when developers try to set instance variables on them. This would give developers a better notion that the object they are using is not a clean/fresh copy like they'd expect it to be from ActiveRecord.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ActiveHash finder behavior described for find and where().first, then compare it with the expected fresh-object behavior in ActiveRecord. Review the proposed cloning approach and the alternative of freezing records; the work is done when the chosen behavior prevents per-request instance state from leaking between returned objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.