Vote #70235
完了Reposman: wrong constant name
0%
説明
I recently upgraded Redmine to version 1.2.0 and now I noticed that reposman stops to work. I call that script every 10 minutes to create git repos for new project.
It ends with a dark message and the -v flag isn't verbose at all! :)
~# ruby /var/www/redmine-1.2/extra/svn/reposman.rb --redmine localhost --svn-dir /repositories/git-root/ --owner www-data --group developers --url /repositories/git-root/ --scm git -v
querying Redmine for projects...
Unable to connect to http://localhost/sys/: wrong constant name Pizzu-dev
I can't understand if the error is due to the "wrong constant name" (which is a git branch) or to the upgrade to 1.2.0
This is my conf:
~# RAILS_ENV=production script/about
About your application's environment
Ruby version 1.8.7 (i486-linux)
RubyGems version 1.3.7
Rack version 1.1.2
Rails version 2.3.11
Active Record version 2.3.11
Active Resource version 2.3.11
Action Mailer version 2.3.11
Active Support version 2.3.11
Application root /var/www/redmine-1.2
Environment production
Database adapter mysql
Database schema version 20110511000000
About your Redmine plugins
Mylyn Connector plugin 2.7.1.stable
journals
--------------------------------------------------------------------------------
Could you try without Mylyn Connector plugin?
--------------------------------------------------------------------------------
same behaviour without the plugin
--------------------------------------------------------------------------------
I can't reproduce.
<pre>
$ ruby extra/svn/reposman.rb --redmine localhost:7000 --svn-dir /tmp/test --owner bbbbb --group bbbbb --url /tmp/test --scm git -v -k 123
querying Redmine for projects...
retrieved 1 projects
treating project Pizzu-dev
Initialized empty shared Git repository in /tmp/test/aaaaaaaa/
repository /tmp/test/aaaaaaaa registered in Redmine with url /tmp/test/aaaaaaaa
repository /tmp/test/aaaaaaaa created
</pre>
--------------------------------------------------------------------------------
The strange fact is that Pizzu-dev isn't a project. We have a git branch with that name (lowercase) and nothing more.
I reproduced it with irb, the error is generated from line 198 of reposman.rb:
irb(main):072:0> projects = Project.find(:all, :params => {:key => $api_key})
NameError: wrong constant name Pizzu-dev
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1373:in `const_defined?'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1373:in `find_or_create_resource_for'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1232:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:965:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1233:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1233:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:965:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1233:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1233:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:965:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1233:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1233:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:1219:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:965:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:889:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:889:in `instantiate_record'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:885:in `instantiate_collection'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:885:in `collect!'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:885:in `instantiate_collection'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:857:in `find_every'
from /usr/lib/ruby/gems/1.8/gems/activeresource-3.0.0/lib/active_resource/base.rb:777:in `find'
from (irb):72
but with the original line, with the $api_key
--------------------------------------------------------------------------------
Sorry, the last line is an error:
-"but with the original line, with the $api_key"-
Just to specify, I uninstalled versions 3.0.0 (rails, activeresource, activerecord, ecc.) and the error is the same:
<pre>
irb(main):082:0> projects = Project.find(:all, :params => {:key => $api_key})
NameError: wrong constant name Pizzu-dev
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1139:in `const_defined?'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1139:in `find_or_create_resource_for'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1040:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:669:in `new'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:669:in `instantiate_record'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:665:in `instantiate_collection'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:665:in `collect!'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:665:in `instantiate_collection'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:642:in `find_every'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:585:in `find'
from (irb):82
from /usr/lib/ruby/1.8/rdoc/markup/simple_markup/inline.rb:150
</pre>
--------------------------------------------------------------------------------
Thinking the problem was the dash '-' in the name of the branch I deleted the branch, but it still dowsn't work, probably because the repository has some merges from that branch to master.
This is really blocking the work in my office, we must create every repo by hand!
--------------------------------------------------------------------------------
Ok, the problem seems ActiveResource (or Module) which can't transform string into constants when there's a dash ('-') or a dot ('.'), I've found a workaround.
In the file /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb, line 1131, change:
resource_name = name.to_s.camelize
with:
resource_name = name.to_s.gsub('-', '_').gsub('.', '_').camelize
I had problem with the dash, but without the second gsub i got the problem:
wrong constant name Release1.0
sho i added the second gsub, probably that string needs more sanitization.
With this workoround reposman works fine, but i think we must understand what's happening here: is a problem with the upgrade to 2.0, is a problem with active_resource or ruby? I bet it's the first option, both ruby and active_record are the same as when reposmen worked well.
Maybe some strings should be formatted before be sent to ActiveResource.
If you give me some hints I can try to fix it
--------------------------------------------------------------------------------
I can not reproduce either. Any error showing up in your Redmine server log file when you run reposman?
--------------------------------------------------------------------------------
Nothing strange from production.log:
Processing SysController#projects to xml (for 127.0.0.1 at 2011-07-03 23:47:00) [GET]
Parameters: {"key"=>"XXXXXXXXXXXXXXXXXX"}
Completed in 659ms (View: 0, DB: 2) | 200 OK [http://localhost/sys/projects.xml?key=XXXXXXXXXXXXXXXXXX]
--------------------------------------------------------------------------------
I have the same problem with a fresh 1.20 installation and svn
Ruby version 1.8.7 (i686-linux)
RubyGems version 1.3.7
Rack version 1.1.1
Rails version 2.3.11
Active Record version 2.3.11
Active Resource version 2.3.11
Action Mailer version 2.3.11
Active Support version 2.3.11
Edge Rails revision unknown
Application root /var/www/railsapp
Environment production
Database adapter mysql
Database schema version 20110511000000
/var/www/railsapp/extra/svn/reposman.rb -t -v -r localhost -s /srv/repos/svn -o www-data -g www-data -u file:///srv/repos/svn --scm subversion
running in test mode
querying Redmine for projects...
Unable to connect to http://localhost/sys/: wrong constant name Devel-20110614
I don't know what is Devel-20110614, is not a project.
--------------------------------------------------------------------------------
I don't know what it is in SVN (in GIT the name was the name of a branch) but the problem is the dash '-' in that name
--------------------------------------------------------------------------------
I confirm this issue. We're using Redmine 1.2.0 with Git repositories.
<pre>
Unable to connect to http://.../sys/: wrong constant name Full-details
</pre>
And "full-details" is a branch in one project.
This started when we upgraded from Redmine 1.1.2 to 1.2.0.
I'm not a Ruby developer but I'm ready to provide informations and test patches to debug this problem.
--------------------------------------------------------------------------------
Problem solved with the upgrade to version 1.2.1
--------------------------------------------------------------------------------
This problem is not resolved in version 1.2.1 of Redmine. I have that version installed on my server, and the error persists. The reposman for GIT doesn't work.
--------------------------------------------------------------------------------
In my case the problem was resolved with the upgrade to 1.2.1, so the cause should be probably searched in a mixture of redmine version, gems installed and some voodoo... :)
--------------------------------------------------------------------------------
I´ve just run into the very same problem with 1.2.0. The update to 1.2.1. did NOT fix the problem. Same error ;-(
Unable to connect to http://myhost.com/redmine/sys/: wrong constant name somebranch-name
As far as I can see it has nothing to do with git or svn -> if you have a branch containing a dash '-' the problem pops up. In our case we want reposman to create a svn repository and the "problem dash branch" which brings up the error is a git repo...
Any ideas?
--------------------------------------------------------------------------------
I have the same problem with version 1.2.1 with branch. The correct gems are installed.
--------------------------------------------------------------------------------
Could someone with a working instance of 1.2.1 post the output of "gem list" and "RAILS_ENV=production script/about", please? Maybe we can isolate the working vs. non-working versions.
We just upgraded to 1.2.1 and the problem is still present. Here's the output of those two commands:
<pre>
# gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.9, 2.3.11, 2.3.5)
actionpack (3.0.9, 2.3.11, 2.3.5)
activemodel (3.0.9)
activerecord (3.0.9, 2.3.11, 2.3.5)
activeresource (3.0.9, 2.3.11, 2.3.5)
activesupport (3.0.9, 2.3.11, 2.3.5)
arel (2.0.10)
builder (3.0.0, 2.1.2)
bundler (1.0.15)
coderay (0.9.8)
erubis (2.6.6)
i18n (0.6.0, 0.5.0, 0.4.2)
mail (2.2.19)
mime-types (1.16)
oniguruma (1.1.0)
plist (3.1.0)
polyglot (0.3.1)
rack (1.3.0, 1.2.3, 1.1.2, 1.0.1)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.9, 2.3.11, 2.3.5)
railties (3.0.9)
rake (0.9.2)
rdoc (3.8)
rubygems-update (1.8.5)
svn2git (2.1.0)
textpow (0.10.1)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.29)
ultraviolet (0.10.2)
</pre>
<pre>
# RAILS_ENV=production script/about
About your application's environment
Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.7
Rack version 1.1.2
Rails version 2.3.11
Active Record version 2.3.11
Active Resource version 2.3.11
Action Mailer version 2.3.11
Active Support version 2.3.11
Application root /var/lib/redmine
Environment production
Database adapter mysql
Database schema version 20110511000000
About your Redmine plugins
Redmine Ultraviolet Syntax highlighting plugin 0.0.3
Redmine DocPu plugin 0.0.2
Redmine Hudson plugin 1.0.7
Redmine Changeset Email Plugin 0.1.0
</pre>
--------------------------------------------------------------------------------
Someone here investigated a bit @reposman.rb@. I don't know if it can help but here's what he found.
@reposman.rb@ defines a @Project@ class which inherits from @ActiveResource::Base@ (line 183). On line 196, the call @Project.find(:all, ...)@ raises the exception. ActiveResource::Base fails to parse the output of "@http://.../sys/projects.xml?key=...@", especially the content of the element "@extra-info@". Fo instance, our @projects.xml@ contains an entry like this:
<pre>
<project>
...
<repository>
<extra-info type="yaml">---
branches:
comments:
last_scmid: 0c9ac39f8d6aa678fa2604cbe3d2254a6db9b366
full-details:
last_scmid: da116c93bc0b010c673f09d2119d072ccb4ccaf5
master:
last_scmid: bd639029d0f193a92cee663b5efca4e3cb493792
db_consistent:
ordering: 0
</extra-info>
...
</repository>
</project></pre>
Note the branch named "@full-details@". If we run reposman.rb, it exits with the following error:
<pre>Unable to connect to http://.../sys/: wrong constant name Full-details</pre>
Here's the full stacktrace we have (same as Tommaso Visconti):
<pre>
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1139:in `const_defined?'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1139:in `find_or_create_resource_for'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1040:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `new'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `new'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `new'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1041:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `each'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:1027:in `load'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:726:in `initialize'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:669:in `new'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:669:in `instantiate_record'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:665:in `instantiate_collection'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:665:in `collect!'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:665:in `instantiate_collection'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:642:in `find_every'
/var/lib/gems/1.8/gems/activeresource-2.3.11/lib/active_resource/base.rb:585:in `find'
/var/lib/redmine/extra/svn/reposman.rb:196
</pre>
--------------------------------------------------------------------------------
We've also run into this problem since we upgraded to Redmine 1.2.1. reposman.rb produces the following output, and refuses to create any new SVN repositories:
<pre>
Unable to connect to https://localhost/redmine/sys/: wrong constant name Flow-based-algo
</pre>
Incidentally, 'flow-based-algo' is the name of a branch we have in a Git repository.
--------------------------------------------------------------------------------
Jean-Sébastien Pédron wrote:
> Someone here investigated a bit @reposman.rb@. I don't know if it can help but here's what he found.
Yes, it seems that it's because it can't properly deserialize the YAML data inside the extra-info field. This extra-info field was added in r5762, so that explains why we're seeing that problem now.
Looking at source:trunk/app/models/repository/git.rb, it should deserialize into a regular Ruby @Hash@, but it looks like Rails is trying to load its contents as ActiveRecord resources. I've added a few @puts@ calls around the @find_or_create_resource_for(key)@ call in @active_resource/base.rb:1040@ and I'm getting this output:
<pre>
Entry: repository -> path_encodingproject_id26url/srv/git/activebpel/id29log_encodingext...
Resource: Project::Repository
Entry: extra_info -> branchesmasterlast_scmidbf2cd48792d2d623eca6ac89029d40948e87ae98add...
Resource: Project::Repository::ExtraInfo
Entry: branches -> masterlast_scmidbf2cd48792d2d623eca6ac89029d40948e87ae98add-jetty-pro...
Resource: Project::Repository::ExtraInfo::Branches
Entry: add-jetty-project -> last_scmid48e6a08d95bf07595c54c07f6e668d13029f6b76
</pre>
I have tried to make sure Rails sees @:extra_info@ as a @Hash@, changing source:trunk/app/models/repository.rb to:
<pre>
serialize :extra_info, Hash
</pre>
but it doesn't seem to make any difference, and it seems like it could have "issues with nil values":http://jqr.github.com/2009/02/01/making-rails-serialize-even-better.html. Am I missing something?
--------------------------------------------------------------------------------
In the end, I had to resort to a similar workaround to note 8. I edited line 1139 of @active_resource/base.rb@ so it read:
<pre>
resource_name = name.to_s.gsub(/\W+/, '_').camelize
</pre>
Basically, this will turn any sequence of non-alphanumerical characters in the key to an underscore.
Shouldn't we report this upstream? I'm not quite sure of how to do it, though: Rails' Github repository doesn't list 2.3.x as a milestone for reporting new issues.
--------------------------------------------------------------------------------
Before I forget: the above workaround is required since ActiveRecord interprets the name of the branch as the name of a class.
--------------------------------------------------------------------------------
I was able to reproduce. Fixed in r7956 by removing extra_info for XML responses as it's not needed by reposman.
--------------------------------------------------------------------------------
Merged in 1.2-stable in r7995.
--------------------------------------------------------------------------------
related_issues
duplicates,Closed,10563,reposman.rb fails to add svn repository when we have one project with git