Forum: Ruby on Rails Troubleshooting "can't modify frozen object" in tzinfo_timez

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Morten (Guest)
on 2007-01-31 03:41
(Received via mailing list)
Hi. Off and on I get a "can't modify frozen object" when working with
the tzinfo_timezone plugin. I've added some debugging in the code to
try and track down what goes wrong:

  def tzinfo
    RAILS_DEFAULT_LOGGER.debug("TZINFO STATE '#{@tzinfo}' class
#{@tzinfo.class} frozen? #{@tzinfo.frozen?}")
    return @tzinfo if @tzinfo
    RAILS_DEFAULT_LOGGER.debug("TZINFO ASSIGN TO #{MAPPING[name]}")
    begin
      @tzinfo = MAPPING[name]
    rescue TypeError => type_error
      RAILS_DEFAULT_LOGGER.debug("TZINFO TYPE ERROR #{type_error}")
      raise type_error
    end
    RAILS_DEFAULT_LOGGER.debug("TZINFO ASSIGNED TO #{@tzinfo}")
    if String === @tzinfo
      @tzinfo = TZInfo::Timezone.get(@tzinfo)
      MAPPING[name] = @tzinfo
    end
    @tzinfo
  end


When the error occurs, the following makes it to the log:

TZINFO STATE '' class NilClass frozen? false
TZINFO ASSIGN TO Europe/Amsterdam
TZINFO TYPE ERROR can't modify frozen object

Which means, that @tzinfo is nil, and yet, the line

    @tzinfo = MAPPING[name]

Causes a TypeError. MAPPING is a hash. I'm mildly confused. Anyone
able to shed some light on what might be the issue or how to dig
further into the problem?

ruby 1.8.4 (2005-12-24) [x86_64-linux]

Thanks.

Morten
Zack C. (Guest)
on 2007-01-31 06:48
(Received via mailing list)
On 1/30/07, Morten <removed_email_address@domain.invalid> wrote:
>     begin
>     @tzinfo
>
> Morten
>
>
> >
>

Morten,

Not sure what's causing this exactly.  Why are you trying to load the
tzinfo from a MAPPING hash?

Check out the timezone code in mephisto for a really slick way to
handle timezones.  It helped me quite a bit.

Hope this helps.

--
Zack C.
http://depixelate.com
Morten (Guest)
on 2007-01-31 19:22
(Received via mailing list)
Zack,

> Morten,
>
> Not sure what's causing this exactly.  Why are you trying to load the
> tzinfo from a MAPPING hash?

The code I'm trying to debug is actually tzinfo_timezone.rb, so the
error occurs within the plugin. I just use it like:

In my user model:

  composed_of :tz, :class_name => 'TimeZone', :mapping => %w(time_zone
name)

In my view:

  <%= format_date(@current_user.tz.utc_to_local(entry.created_at)) %>

The hash is part of tzinfo_timezone.rb's way of associating time zones
with locations.

Thanks for the tip on Mephisto, I'll look into their way og handling
time zones.

Br,

Morten
Zack C. (Guest)
on 2007-01-31 19:44
(Received via mailing list)
On 1/31/07, Morten <removed_email_address@domain.invalid> wrote:
> error occurs within the plugin. I just use it like:
> The hash is part of tzinfo_timezone.rb's way of associating time zones
> with locations.
>
> Thanks for the tip on Mephisto, I'll look into their way og handling
> time zones.

This line should be:

composed_of :tz, :class_name => 'TzinfoTimezone', :mapping =>
%w(time_zone name)

I think the mappings are slightly different between the two which
would explain the intermittent crashes.

--
Zack C.
http://depixelate.com
Tieg (Guest)
on 2007-02-12 03:20
(Received via mailing list)
The tzinfo_timezone plugin, in the init.rb script, actually replaces
Rails' TimeZone class with TzinfoTimezone, so using either one of
those should work as the :class_name (I think?),

-tieg
Guest (Guest)
on 2007-06-26 01:42
Morten wrote:
> Hi. Off and on I get a "can't modify frozen object" when working with
> the tzinfo_timezone plugin. I've added some debugging in the code to
> try and track down what goes wrong:
>
> .....
>
> Thanks.
>
> Morten

Has anybody figured out why this occurs and how to fix it?  It's odd
that the error only occurs sporadically.

Thanks,
Andrew
This topic is locked and can not be replied to.