Restore frozen state on rollback, fixes #6417 #6420

Merged
merged 1 commit into from May 22, 2012

Conversation

Projects
None yet
2 participants
Member

chancancode commented May 21, 2012

My first patch for rails!

When saving a frozen? record, active record would raise an exception to complain about the frozen attributes, rollback the transaction. However, it also has the side effect of unfreezing the record after the rollback. This behaviour is undesirable and incorrect (saving a frozen? record twice in a roll would fail for the first time and succeed in the second time). This patch fixes the bug by explicitly restoring the frozen? state after a rollback.

Member

drogus commented May 21, 2012

Can you add a few lines of explanation in commit message? Short description of behavior that this commit fixes.

Member

chancancode commented May 21, 2012

Rebased and fixed the commit message. Is this better?

Member

drogus commented May 21, 2012

Sorry for being picky, but can you do it according to info added here: ae8b09c?

@chancancode chancancode Restore the frozen state on rollback. Fixes #6417.
Currently, when saving a frozen record, an exception would be thrown
which causes a rollback. However, there is a bug in active record that
"defrost" the record as a side effect:

    >> t = Topic.new
    => #<Topic id: nil, ...>
    >> t.freeze
    => #<Topic id: nil, ...>
    >> t.save
    RuntimeError: can't modify a frozen Hash
    >> t.frozen?
    => false
    >> t.save
    => true

This patch fixes the bug by explictly restoring the frozen state on the
attributes Hash after every rollback.
cb847b9
Member

chancancode commented May 21, 2012

No worries, thanks for updating the docs. I was just looking through the pull requests for an example this morning. Can you review the message?

Member

drogus commented May 22, 2012

@chancancode looks great!

@drogus drogus added a commit that referenced this pull request May 22, 2012

@drogus drogus Merge pull request #6420 from chancancode/master_restore_frozen_state…
…_on_rollback

Restore frozen state on rollback, fixes #6417
1447aca

@drogus drogus merged commit 1447aca into rails:master May 22, 2012

Member

chancancode commented May 22, 2012

@drogus Thanks for the merge <3<3<3

Is this a valid candidate for a 3-2-stable backport? If so, should I apply the patch to 3-2-stable and open a separate pull request? I was trying to look up the rules/workflow for that but I couldn't seem to find that anywhere. If you can briefly explain it I could update the guides via docrails.

Member

drogus commented May 22, 2012

@chancancode yes, please open pull request. Basically, the general rule is that we can backport bugfixes and security fixes. Backports are sometimes skipped, especially if it's hard to backport and issue is not critical. There are no strict rules about this mostly because it depends on specific cases and on contributors - sometimes there is no interest in backporting a fix.

@chancancode chancancode added a commit to chancancode/rails that referenced this pull request May 22, 2012

@chancancode chancancode Restore the frozen state on rollback. Fixes #6417.
This is a 3-2-stable backport for #6420 which was merged into master.

Currently, when saving a frozen record, an exception would be thrown
which causes a rollback. However, there is a bug in active record that
"defrost" the record as a side effect:

    >> t = Topic.new
    => #<Topic id: nil, ...>
    >> t.freeze
    => #<Topic id: nil, ...>
    >> t.save
    RuntimeError: can't modify a frozen Hash
    >> t.frozen?
    => false
    >> t.save
    => true

This patch fixes the bug by explictly restoring the frozen state on the
attributes Hash after every rollback.
a543002

@rafaelfranca rafaelfranca added a commit that referenced this pull request May 22, 2012

@rafaelfranca rafaelfranca Merge pull request #6445 from chancancode/3-2-stable_restore_frozen_s…
…tate_on_rollback

Restore the frozen state on rollback. (Backports #6420)
9ee8528

@chancancode chancancode added a commit to chancancode/rails that referenced this pull request May 23, 2012

@chancancode chancancode Added instructions for backporting changes to guides.
I was looking for instructions on backporting changes the other day and
wasn't able to find it anywhere. I updated the contrib guides based on
the disccusion in #6420, #6215 and #6447.
c97fb88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment