#35 √ invalid
Shay Arnett

Removal of constants during reload breaks model class equality between unreloaded code and reloaded code

Reported by Shay Arnett | February 11th, 2008 @ 11:05 PM | in 0.9.4

Originally posted on Trac by qslack@qslack.com

Original Trac Ticket

Description

The problem - reproducible with any DM/Sequel model (maybe AR too)

$ merb -i

>> Article.object_id

=> 12454570

  1. NOW go to article.rb and save the file (cmd-S/etc.).
  2. you don't need to alter the file to see this behavior.

>> Article.object_id

=> 22273090

Example

This breaks things in a case like:

  • if you do some_obj.is_a? Article in a helper or controller and then the model is reloaded, any requests after that fail even if some_obj.class is Article, because the Articles (the one being tested for in is_a? on one hand, and the class of any objects instantiated after the reload) have different object_ids

Culprit

merb/server.rb line 352 is Merb::Server#remove_constant. This deletion of constants is the intended behavior, but this is certainly not an intended side effect.

Fix?

Not sure. For comparison, Rails' reloading code is in activesupport/lib/active_support/dependencies.rb (load_missing_constant at line 221 and Class#const_missing at like 463 seem to me to be the most relevant parts)

Trac Attachments

Trac Comments

01/03/08 16:35:31 changed by qslack@qslack.com

Workaround

A s

    01/03/08 16:35:31 changed by qslack@qslack.com

    priority changed from medium to major.

  Workaround

A s

    priority changed from medium to major.
    
   

Comments and changes to this ticket

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) February 27th, 2008 @ 01:48 AM

    • → State changed from “new” to “open”

    I don't see why this should fail in future requests, since Article will get re-evaluated in the new context. Or am I missing something?

  • Ezra Zygmuntowicz

    Ezra Zygmuntowicz March 4th, 2008 @ 11:16 PM

    • → Assigned user changed from “” to “Wayne Seguin”
    • → Milestone changed from “” to “0.9.4”
  • Michael Klishin (antares)

    Michael Klishin (antares) August 2nd, 2008 @ 06:52 PM

    • → Tag changed from “” to “bootloader merb”
    • → State changed from “open” to “invalid”

    I think this issue is present in rails and any other class reloader. There's a way to fix it but it would cause huge complication of bootloader (it's to track class object ids on first load and re-assign constants) and will cause a huge amount of warnings from Ruby VM that should be supressed.

    Looks like not worth it to me.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »