Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

ActiveSupport has undeclared dependency on tzinfo #4909

Closed
awendt opened this Issue · 8 comments

5 participants

@awendt

I upgraded an app from Rails 3.0.x to 3.2.1 and got:

You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install
/Users/andrewen/.gem/ruby/1.8/gems/activesupport-3.2.1/lib/active_support/core_ext/time/zones.rb:60:in `find_zone!': uninitialized constant TZInfo (NameError)

Turns out said app does not bundle the activerecord gem.

This problem does not appear in a fresh app generated with --skip-active-record because AR is bundled but not required in application.rb — AR depends on tzinfo which fixes the undeclared dependency by accident.

@kennyj
Collaborator

I found reference to TZInfo in active_support, but I couldn't find reference to TZInfo in active_record.
I think that we should move dependency on tzinfo from active_record to active_support. Please see follwing commit.

Am I wrong ?

@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@awendt

Did not verify it, but that makes sense. Are you going to create a pull request?

@kennyj
Collaborator

Yes, I'll send PR.

I found steps to reproduce for acitvesupport.

$ cd (path to rails)
$ git checkout master
$ rake build
$ ls -la pkg
...
-rw-rw-r--  1 kennyj kennyj  306688  1月 12 01:13 activesupport-4.0.0.beta.gem
...

$ gem install pkg/activesupport-4.0.0.beta.gem --no-ri --no-rdoc

$ cd (path to work)
$ vim Gemfile
source 'http://rubygems.org'
gem 'activesupport', '4.0.0.beta'
$ bundle install
$ bundle exec irb

■before
ruby-1.9.3-p0 :001 > require 'active_support/all'
 => true
ruby-1.9.3-p0 :002 > Time.find_zone!("Tokyo")
You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install
NameError: uninitialized constant Class::TZInfo
        from /home/kennyj/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-4.0.0.beta/lib/active_support/core_ext/time/zones.rb:60:in `rescue in find_zone!'
        from /home/kennyj/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-4.0.0.beta/lib/active_support/core_ext/time/zones.rb:53:in `find_zone!'
        from (irb):2
        from /home/kennyj/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'

■after (with myfix)
ruby-1.9.3-p0 :001 > require 'active_support/all'
 => true
ruby-1.9.3-p0 :002 > Time.find_zone!("Tokyo")
 => (GMT+09:00) Tokyo

and for activerecord

~/rails(fix_4909)$ cd activerecord/
~/rails/activerecord(fix_4909)$ find . -name "*" -print | xargs grep "tzinfo"
./CHANGELOG.md:*   Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled *Geoff Buesing*
~/rails/activerecord(fix_4909)$ find . -name "*" -print | xargs grep "TZInfo"
./CHANGELOG.md:*   Removing unnecessary uses_tzinfo helper from tests, given that TZInfo is now bundled *Geoff Buesing*
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kennyj kennyj referenced this issue from a commit in kennyj/rails
@kennyj kennyj Fix GH #4909. Dependency on TZInfo move from AR to AS. 63dc9b4
@kennyj
Collaborator

@awendt
I'm closing this issue, because the aboe PR is meged.
If you have any problem, please comment to this issue :-)

Thanks

@kennyj kennyj closed this
@kennyj kennyj referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@joelhoffman joelhoffman referenced this issue from a commit
@tenderlove tenderlove Merge branch 'master' into instance_reader
* master: (30 commits)
  Bump tzinfo. 0.3.31 was released on November 6, 2011.
  Fix GH #4909. Dependency on TZInfo move from AR to AS.
  moving ordered hash to normal hash because ruby 1.9.3 hash defaultly ordered one
  Refactored the OrderedHash related stuff
  Replaced OrderedHash usage with Ruby 1.9 Hash
  Replaced OrderedHash with Hash for ruby 1.9 series
  removed unnecessary code
  replacing the orderhash with hash for ruby-1.9
  Clean up some wording.
  Fix typo.
  test title changed corresponding to the test
  replaced active support ordered hash to ruby hash on active resource
  PostgreSQL does not work in the same way of the other adapters
  AR::Relation#pluck: improve to work with joins
  Fix match docs
  Fix attribute_before_type_cast for serialized attributes. Fixes #4837.
  Fix failing request test
  Fixes in AMo README
  Update README to mention lint.
  Trim down Active Model API by removing valid? and errors.full_messages
  ...
e0cba3a
@Gawyn

I had exactly this issue in 3.2.13. Is it resolved?

@pixeltrix
Owner

Actually, moving the dependency from Active Record to Active Support breaks the original intention of the code. Whilst Active Support's primary purpose is to provide common code abstractions for Rails it can be used in a pick & mix way by other applications/libraries only requiring what they need from it. By moving the dependency to Active Support we've forced the tzinfo gem on all users of it, whether you are using it's date and time methods or not.

@pixeltrix
Owner

Also putting in a hard dependency like ~> 0.3.31 leads to problems like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.