Skip to content

Memoization can cause multiple records to share an attributes hash #246

@eugeneius

Description

@eugeneius

When memoization is enabled, the same coder hash is used to instantiate multiple objects when a record is fetched multiple times. The data is passed to #init_with without being duplicated, which also just assigns the hash directly.

Here's a test case demonstrating how this behaviour caused a bug in our application: https://gist.github.com/e644d420da97dfc0b920

The title attribute is assigned on one record, but not saved. This updates the value in the attributes hash, but doesn't write it to the database. When the record is fetched again, it gets the same attributes hash, including the updated title attribute. We try to update the attribute on this new record, but the new value is the same as the existing one and Active Record optimises away the update.

This problem was actually fixed by #242, as the attributes hash is now duplicated every time a record is created. However the bug is still present in the latest released version, v0.2.5.

Since the worst case here is pretty bad (lost updates!) it would be great to either publish a new release from master to get the fix in #242, or do a bugfix release just to address this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions