Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning: circular require considered harmful. #7650

Merged
merged 1 commit into from Oct 7, 2012

Conversation

kennyj
Copy link
Contributor

@kennyj kennyj commented Sep 15, 2012

I saw some warning when executing rails own testcases.

I don't know 8b05cfa is best way ;)
Please review it !

@@ -6,6 +6,8 @@ class Admin::User < ActiveRecord::Base
store :json_data, :accessors => [ :height, :weight ], :coder => JSON
store :json_data_empty, :accessors => [ :is_a_good_guy ], :coder => JSON

undef :phone_number, :phone_number=
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is better to remove :phone_number from the store_accessor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In first, I removed it. But I got test failure.

  1) Failure:
test_0020_all stored attributes are returned(StoreTest) [test/cases/store_test.rb:139]:
--- expected
+++ actual
@@ -1 +1 @@
-[:color, :homepage, :favorite_food, :phone_number]
+[:color, :homepage, :favorite_food]

If remove one, the following lines aren't executed.

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/store.rb#L88-89

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the warning will be showed either in the application so I don't think we should define the store_attribute and also the custom accessor. If this test fails we can remove :phone_number from the assertion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. I'll change this.

@kennyj
Copy link
Contributor Author

kennyj commented Sep 19, 2012

I updated and rebased.

@fxn please comment this especially 2a6f57f ?

@rafaelfranca
Copy link
Member

@kennyj I cherry picked 1f42db8. Could you update this pull request to include only 2a6f57f?

@kennyj
Copy link
Contributor Author

kennyj commented Oct 2, 2012

@rafaelfranca done.

@fxn
Copy link
Member

fxn commented Oct 4, 2012

Hi, two questions over here:

  1. I have run the AS test suite and see some warnings, but none of them seem related to this. Have also run ruby -W -Ilib lib/active_support/deprecation.rb and see no warning. How to you get them?
  2. When this file is evaluated, since the require calls are moved to the body of the class they are still being executed when the file is interpreted, as they did in the top level. How can this patch change anything related to circular dependencies?

@rafaelfranca
Copy link
Member

  1. Active Model and Active Record suites show the warning.

@fxn
Copy link
Member

fxn commented Oct 4, 2012

The interesting thing is that the warning is raised after the Deprecation class is defined. After following backtraces I have tracked down the issue to this (executed under activesupport):

$ ruby -W -Ilib -ractive_support -ractive_support/deprecation -e1

and seem to be related to the fact that active_support.rb sets an autoload for :Deprecation. I bet something funky is going on related to autoload. I'll leave it for tonight, will keep you guys posted interesting puzzle :).

@kennyj
Copy link
Contributor Author

kennyj commented Oct 5, 2012

@fxn

  1. When executing rake test in the activerecord, we got this error.
  2. I suspect the cause of problem is auctoload :Deprecation.
    first, we require active_support/deprecation.
    second we require active_support/derecation/instance_delegator (example) in the active_support/deprecation,
    third in the instance_delegator.rb, we reference ActiveSupport::Deprecation, that is the target of autoload.
    I have same recognition that you mentioned in the second comment.

BTW: In the first draft about this PR,

class ActiveSupport::Deprecation; end # ★added
require 'active_support/core_ext/module/deprecation'
require 'active_support/deprecation/instance_delegator'
require 'active_support/deprecation/behaviors'
require 'active_support/deprecation/reporting'
require 'active_support/deprecation/method_wrappers'
require 'active_support/deprecation/proxy_wrappers'
require 'singleton'

module ActiveSupport
  # \Deprecation specifies the API used by Rails to deprecate methods, instance
  # variables, objects and constants.
  class Deprecation
    include Singleton

@fxn
Copy link
Member

fxn commented Oct 7, 2012

I can't think of a better way to avoid this warning. Everything seems used just fine, problem is since we defer loading to autoload, the first time you try to define the constant the autoload is triggered, so generally speaking you reopen the constant if you are in a different file.

I'll keep thinking about it, but let's merge. I'll add a comment later.

fxn added a commit that referenced this pull request Oct 7, 2012
Fix warning: circular require considered harmful.
@fxn fxn merged commit e0deb0e into rails:master Oct 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants