Feature #14534

Upgrade to Rails 4.2

Added by Marwan Rabbaa over 4 years ago. Updated about 2 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Rails support
Target version:3.0.0
Resolution:Fixed

Description

Hi,

I want to run redmine on rails 4.
For me (a rails / ruby newbie), it was not a short time task ;), but I'm shure i will rage against this with you help.

I want completed 4 steps, and with it I can run my application, but I have a HTTP/500 error on the welcome controller.

Started GET "/" for 83.217.232.12 at 2013-07-24 13:38:04 +0200
Processing by WelcomeController#index as HTML
WARNING: Can't mass-assign protected attributes for Setting: name
        app/models/setting.rb:173:in `find_or_default'
        app/models/setting.rb:108:in `[]'
        app/models/setting.rb:141:in `rest_api_enabled?'
        app/controllers/application_controller.rb:106:in `find_current_user'
        app/controllers/application_controller.rb:87:in `user_setup'
Completed 500 Internal Server Error in 3ms

NoMethodError (undefined method `[]' for nil:NilClass):
  app/models/setting.rb:95:in `value'
  app/models/setting.rb:108:in `[]'
  app/models/setting.rb:141:in `rest_api_enabled?'
  app/controllers/application_controller.rb:106:in `find_current_user'
  app/controllers/application_controller.rb:87:in `user_setup'

  • Firstly I remove version called in Gemfile for thos gems * rails * jquery-rails * i18n * coderay * fastercsv * builder
  • Secondly, I have added 3 gems (because remove on rails core, for fourth version of this framework). * gem "protected_attributes" * gem "actionpack-action_caching", github: "rails/actionpack-action_caching" * gem "rails-observer"
  • Thirdly, I have added config.eager_load to config/environments/*.rb (true on production, false on else)
  • Fourthly (and I'm not sure of this), I have remove 3 migrations (I have ot skill to rewrite them) * 105_build_projects_tree.rb * 018_set_doc_and_files_notifications.rb * 20110228000100_copy_repositories_log_encoding.rb

Have you ever tried to migrate redmine to rails 4


Related issues

Related to Redmine - Feature #15367: Replace outdated awesome_nested_set by gem Closed
Related to Redmine - Feature #14371: Drop Ruby 1.8.7 support Closed
Related to Redmine - Feature #12097: Multi Thread Support Closed
Related to Redmine - Defect #18174: Rails-4.1 branch merge into trunk (r13482) reverts trunk ... Closed
Related to Redmine - Defect #18192: LDAP tests not running with Rails 4.1 Closed
Related to Redmine - Defect #18429: Error raised on project settings after project wiki is de... Closed
Related to Redmine - Defect #18275: First argument in form cannot contain nil or be empty err... Closed
Duplicated by Redmine - Feature #14907: Rails 4.0 Support Closed

Associated revisions

Revision 13232
Added by Jean-Philippe Lang over 3 years ago

Rails 4.1 branch

Revision 13233
Added by Jean-Philippe Lang over 3 years ago

Test suite passes with Rails 4.1.

Revision 13234
Added by Jean-Philippe Lang over 3 years ago

Fixed error on Project.rebuild_tree! during migration (#14534).

Revision 13235
Added by Jean-Philippe Lang over 3 years ago

Fixed default admin account creation during migration (#14534).

Revision 13482
Added by Jean-Philippe Lang about 3 years ago

Merged rails-4.1 branch (#14534).

Revision 13490
Added by Jean-Philippe Lang about 3 years ago

Fixed an SQL error with SQLServer (#14534).

Revision 13502
Added by Toshi MARUYAMA about 3 years ago

fix ja.yml and zh-TW.yml merge mistake of r13482 (#14534)

Revision 13544
Added by Jean-Philippe Lang about 3 years ago

Make sure that invalid cache from older versions is not used for languages_options (#14534).

Revision 13790
Added by Jean-Philippe Lang almost 3 years ago

XML parameters parser extracted to actionpack-xml_parser gem in Rails 4 (#14534).

Revision 13892
Added by Jean-Philippe Lang almost 3 years ago

Upgrade to Rails 4.2.0 (#14534).

Revision 13894
Added by Jean-Philippe Lang almost 3 years ago

Fix migration and use Rails 4.2.0 release (#14534).

Revision 13896
Added by Jean-Philippe Lang almost 3 years ago

Use attribute writers instead of before_create callback to normalize comments and committer (#14534).

Unlike other adapters, SQLite raises Encoding::UndefinedConversionError before the callback that reencodes attributes is called.

Revision 13902
Added by Jean-Philippe Lang almost 3 years ago

Make sure that #scm_iconv returns a string with the target encoding (#14534).

filechanges.find_by_revision_and_path fails with SQLite if arguments are not UTF-8 encoded.

Revision 13943
Added by Jean-Philippe Lang almost 3 years ago

Require rbpdf 1.18.5 that is Rails 4.2 compatible (#14534).

Revision 14145
Added by Toshi MARUYAMA over 2 years ago

Merged r14136 from trunk to 3.0-stable.

revert r13896 (#14534)

History

#1 Updated by Toshi MARUYAMA over 4 years ago

  • Subject changed from Running redmine on rails 4 to Rails 4 porting
  • Priority changed from Urgent to Normal

#2 Updated by Sergiy Nazarov about 4 years ago

#14907 - migrate redmine to rails 4

#3 Updated by Toshi MARUYAMA about 4 years ago

#4 Updated by Toshi MARUYAMA about 4 years ago

#5 Updated by Toshi MARUYAMA about 4 years ago

#6 Updated by Ondřej Surý about 4 years ago

Hi,

just checking if there's a plan to add the Rails 4 support yet to do some next-stable Debian release planning.

New rack 1.5 broke rails-3.2, and we would really like to release next stable Debian with as latest rails release as possible by our reverse dependencies.

There's still some time left (about a year) before the archive is frozen, but I would like to be assured that everything will be solved by that time.

Thanks,
O.

#7 Updated by Toshi MARUYAMA almost 4 years ago

#9 Updated by Toshi MARUYAMA almost 4 years ago

I rebased on r12470.

These are unit test results.

Rais4 uses strong parameter by default.
But, Redmine has many ActiveRecord.new and ActiveRecord.create at tests.
For examples: source:tags/2.4.2/test/unit/issue_test.rb#L52

So, I use config.active_record.whitelist_attributes = false.

#10 Updated by Toshi MARUYAMA almost 4 years ago

I rebased on r12644.

I removed almost all deprecating warnings.
But, awesome_nested_set and acts_as_activity_provider have many deprecating warnings.
So, I use ActiveSupport::Deprecation.silence.

  ActiveSupport::Deprecation.silence do
    scope.all(provider_options[:find_options].dup)
  end

awesome_nested_set master branch requires Rails4.
https://travis-ci.org/marutosi/redmine/builds/16771785

Redmine on Rails3 tests fail on awesome_nested_set 2-1-stable branch.
https://travis-ci.org/marutosi/redmine/builds/16771672

#11 Updated by Toshi MARUYAMA almost 4 years ago

  • Related to Feature #15367: Replace outdated awesome_nested_set by gem added

#12 Updated by Jean-Philippe Lang almost 4 years ago

  • Subject changed from Rails 4 porting to Upgrade to Rails 4
  • Target version set to 3.0.0

#13 Updated by Toshi MARUYAMA almost 4 years ago

I rebased on trunk r12884.

Previous revision uses awesome_nested_set 2.1.6 removing Rails4 deprecate warning.

Gemfile:

gem "awesome_nested_set",
    :git => "git://github.com/marutosi/awesome_nested_set.git",
    # PR 230, 231 and 232
    :ref => "4c4fdfe80f7451b" 

So, DB migration of PostgreSQL fails.
https://travis-ci.org/marutosi/redmine/jobs/18922993

== 105 BuildProjectsTree: migrating ===========================================

rake aborted!

An error has occurred, this and all later migrations canceled:

PG::GroupingError: ERROR: column "projects.id" must appear
 in the GROUP BY clause or be used in an aggregate function

LINE 1: ...lft" HAVING COUNT("projects"."lft") > 1 ORDER BY "projects"...
^

: SELECT "projects"."lft", COUNT("projects"."lft") FROM "projects" 
 GROUP BY "projects"."lft" HAVING COUNT("projects"."lft") > 1
 ORDER BY "projects"."id" ASC LIMIT 1
 /home/travis/.rvm/gems/ruby-1.9.3-p484/bundler/gems/rails-702f3dca61f1/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:791:in `async_exec'

awesome_nested_set master branch and 2-1-stable branch have regression.

So, tests using awesome_nested_set master branch fails.

#14 Updated by Jean-Philippe Lang almost 4 years ago

Gemfile:

 gem "awesome_nested_set",
 :git => "git://github.com/marutosi/awesome_nested_set.git",
 # PR 230, 231 and 232
 :ref => "4c4fdfe80f7451b" 
 

I don't like that, we should either use the official gem or bundle it in Redmine as it was before with the appropriate fix.

#16 Updated by Ondřej Surý over 3 years ago

JFTR now that rails 4.1 is out - redmine should target rails 4.1 instead of rails 4.0.

Do you have any idea when that happens?

#17 Updated by Jean-Philippe Lang over 3 years ago

  • Subject changed from Upgrade to Rails 4 to Upgrade to Rails 4.1

4.1 indeed. It should happen in fall.

#18 Updated by Jean-Philippe Lang over 3 years ago

@Toshi, we're not targeting Rails 4.0. The branch /sandbox/rails-4.1 is working with Rails 4.1, please don't make changes for 4.0 compatibility/warnings.

#19 Updated by Toshi MARUYAMA over 3 years ago

Sorry.
I need feedback to Rails team that JPL fixed this Rails 4.0 issue.
https://github.com/rails/rails/issues/15471

And I need feedback to awesome_nested_set author.
https://github.com/collectiveidea/awesome_nested_set/pull/242

There is only one DEPRECATION WARNING on Rails 4.0.
https://travis-ci.org/marutosi/redmine/jobs/29510718#L2074

DEPRECATION WARNING: You didn't set config.secret_key_base.
Read the upgrade documentation to learn more about this new config option.
(called from env_config
 at /home/travis/.rvm/gems/ruby-1.9.3-p545/gems/railties-4.0.8/lib/rails/application.rb:141)

#20 Updated by Toshi MARUYAMA over 3 years ago

On r13312, some tests fail on Travis.
https://travis-ci.org/marutosi/redmine-bb/jobs/29816929

On my console, following test fails

$ ruby test/unit/issue_test.rb
  1) Failure:
IssueTest#test_visible_scope_for_member_with_groups_should_return_assigned_issues [test/unit/issue_test.rb:295]:
Failed assertion, no message given.

#21 Updated by Saimon Lovell over 3 years ago

Any news on if RedMine will migrate to Rails 4.1?
So far there has been 3 updates (4.1.4) over time and changes are not feature breaking.
I would recommend now would be a good time to start migrating to rails 4.1

I am going to give it a shot and see how far I can go.

#22 Updated by Toshi MARUYAMA over 3 years ago

#23 Updated by Robert Weclawski about 3 years ago

Saimon Lovell wrote:

Any news on if RedMine will migrate to Rails 4.1?
So far there has been 3 updates (4.1.4) over time and changes are not feature breaking.
I would recommend now would be a good time to start migrating to rails 4.1

I am going to give it a shot and see how far I can go.

Hi Saimon,
any progress on that ? If you got some repo on github for that please let me know.
I would be quite happy if I could help.

--
Regards,
Robert

#24 Updated by Toshi MARUYAMA about 3 years ago

Robert Weclawski wrote:

any progress on that ? If you got some repo on github for that please let me know.

#25 Updated by Toshi MARUYAMA about 3 years ago

#26 Updated by Toshi MARUYAMA about 3 years ago

#27 Updated by Jean-Philippe Lang about 3 years ago

  • Related to Defect #18174: Rails-4.1 branch merge into trunk (r13482) reverts trunk commits added

#28 Updated by Jean-Philippe Lang about 3 years ago

  • Status changed from New to Closed
  • Resolution set to Fixed

#29 Updated by Jean-Philippe Lang about 3 years ago

  • Related to Defect #18192: LDAP tests not running with Rails 4.1 added

#30 Updated by Jean-Philippe Lang about 3 years ago

  • Related to Defect #18429: Error raised on project settings after project wiki is deleted added

#31 Updated by Jean-Philippe Lang about 3 years ago

  • Related to Defect #18275: First argument in form cannot contain nil or be empty error on revision view added

#32 Updated by Jean-Philippe Lang almost 3 years ago

  • Subject changed from Upgrade to Rails 4.1 to Upgrade to Rails 4.2
  • Status changed from Closed to Reopened

Rails 4.2 is about to be released and will be the last 4.x branch. When Rails 5 is out, only Rails 4.2 will get bug fixes (security fixes only for previous versions). So we should target Rails 4.2 for Redmine 3.x.

#33 Updated by Jean-Philippe Lang almost 3 years ago

I've done the upgrade to Rails 4.2 (not yet committed) but there are still some issues:

  • the rbpdf gem uses ActionView::Base.sanitized_allowed_css_properties= which is deprecated in Rails 4.2

#34 Updated by Toshi MARUYAMA almost 3 years ago

Jean-Philippe Lang wrote:

I reported awesome_nested_set 3.0.1 break Redmine.
https://github.com/collectiveidea/awesome_nested_set/issues/280

#35 Updated by Toshi MARUYAMA almost 3 years ago

  • Resolution deleted (Fixed)

#36 Updated by Jean-Philippe Lang almost 3 years ago

Toshi MARUYAMA wrote:

I reported awesome_nested_set 3.0.1 break Redmine.
https://github.com/collectiveidea/awesome_nested_set/issues/280

The error you reported should be fixed in Redmine.

The error with awesome_nested_set 3.0.1 and Rails4.2 is: NoMethodError: undefined method `join_sql' for #<Arel::SelectManager:0xa907c58>. #join_sql was replaced in the above commit:
https://github.com/collectiveidea/awesome_nested_set/commit/2f3f28baf71f4964cedcc2548b51e2a4671e8e10

#37 Updated by Mischa The Evil almost 3 years ago

Jean-Philippe Lang wrote:

I've done the upgrade to Rails 4.2 (not yet committed) but there are still some issues:

This is no longer an issue due to #18860.

  • the rbpdf gem uses ActionView::Base.sanitized_allowed_css_properties= which is deprecated in Rails 4.2

I've relayed this issue to Jun as https://github.com/naitoh/rbpdf/issues/8.

#38 Updated by Toshi MARUYAMA almost 3 years ago

On r13893, PostgreSQL migration fails.

https://travis-ci.org/marutosi/redmine-bb/jobs/47402990#L1278

== 20091114105931 AddViewIssuesPermission: migrating ==========================

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

can't convert Symbol into String
/home/travis/build/marutosi/redmine-bb/app/models/role.rb:99:in `include?'

#39 Updated by Toshi MARUYAMA almost 3 years ago

I have created issue on Rails GitHub.

Rails 4.2 SQLite3 regression: Encoding::UndefinedConversionError: "\xE9" from ASCII-8BIT to UTF-8
https://github.com/rails/rails/issues/18580

#40 Updated by Jean-Philippe Lang almost 3 years ago

I've reported another regression with sqlite:
https://github.com/rails/rails/issues/18585

#41 Updated by Toshi MARUYAMA almost 3 years ago

On console, IssueTest#test_visible_scope_for_member_with_groups_should_return_assigned_issues always fails.

  1) Failure:
IssueTest#test_visible_scope_for_member_with_groups_should_return_assigned_issues [test/unit/issue_test.rb:324]:
Failed assertion, no message given.

#42 Updated by Jun NAITOH almost 3 years ago

Mischa The Evil wrote:

Jean-Philippe Lang wrote:

  • the rbpdf gem uses ActionView::Base.sanitized_allowed_css_properties= which is deprecated in Rails 4.2

I've relayed this issue to Jun as https://github.com/naitoh/rbpdf/issues/8.

This problem fixed by rbpdf 1.18.5.
please bundle update.

#43 Updated by Jean-Philippe Lang almost 3 years ago

Jun NAITOH wrote:

This problem fixed by rbpdf 1.18.5.
please bundle update.

Gemfile updated to ~>1.18.5, thanks!

#44 Updated by Jean-Philippe Lang almost 3 years ago

  • Status changed from Reopened to Closed
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

SQLServer compatibility is now fixed.

#45 Updated by Toshi MARUYAMA almost 3 years ago

This issue is closed and we dropped awesome_nested_set gem (#18860) in 3.0.0.
But I record some my works.

Jean-Philippe Lang wrote:

Toshi MARUYAMA wrote:

I reported awesome_nested_set 3.0.1 break Redmine.
https://github.com/collectiveidea/awesome_nested_set/issues/280

The error you reported should be fixed in Redmine.

Following change fixes on Redmine trunk r13839 (last trunk revision with awesome_nested_set)
with awesome_nested_set 3.0.1.

diff --git a/app/models/issue.rb b/app/models/issue.rb
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -185,7 +185,7 @@ class Issue < ActiveRecord::Base
   # the lock_version condition should not be an issue but we handle it.
   def destroy
     super
-  rescue ActiveRecord::RecordNotFound
+  rescue ActiveRecord::StaleObjectError, ActiveRecord::RecordNotFound
     # Stale or already deleted
     begin
       reload

But awesome_nested_set 3.0.2 breaks Redmine.

  1) Error:
IssueTest#test_visible_and_nested_set_scopes:
ActiveRecord::ActiveRecordError: Impossible move, target node cannot be inside moved tree.
    app/models/issue.rb:1374:in `update_nested_set_attributes'
    app/models/issue.rb:173:in `create_or_update'
    test/object_helpers.rb:93:in `generate!'
    test/unit/issue_test.rb:360:in `test_visible_and_nested_set_scopes'

This is caused by this change.
https://github.com/collectiveidea/awesome_nested_set/commit/87d8c7cc94eadf08

#46 Updated by Etienne Massip over 2 years ago

Jean-Philippe Lang wrote:

SQLServer compatibility is now fixed.

As Toshi noticed (Redmine 3.0 problem with MSSQL 2008) they chose to break compatibility with MSSQL < 2012 which is a bit brutal.

Specifying Rails ~> 4.1 in Gemfile seems to do the trick with trunk @ r14520, do you know if some of the changes that were made when switching from 4.1 to 4.2 aren't 4.1 compatible?

#47 Updated by Toshi MARUYAMA about 2 years ago

Etienne Massip wrote:

Specifying Rails ~> 4.1 in Gemfile seems ...

FTR: #20603

Also available in: Atom PDF