Gitorious: Inconsistent Database

Gitorious uses MySQL to store project, repository and user information as well as connection between those three data blocks. It all works well until you have a problem and need to fix things in the database yourself, i.e. when creating a repository doesn't finish and you have no way to delete it via the GUI.

In such cases, you are likely to miss deleting references to the repository, user or project you just deleted - and nobody will warn you since Gitorious doesn't use foreign key constraints like ON DELETE. This is especially annoying because Gitorious is really bitchy and crashes when the referential integrity of the database is violated.

I opened a feature request and talked with the Gitorious devs on IRC; they said they followed the Rails recommendations which state that database integrity is task of the application and not the database...

Here are some of those errors along with an explanation what is wrong:

undefined method `user' for nil:NilClass


125:       
    126: <% @favorites.each do |favorite| %> 127:
  • 128: <%= link_to_watchable(favorite) -%> 129:
  • 130: <% end %> app/helpers/favorites_helper.rb:88:in `css_classes_for' app/views/site/dashboard.html.erb:127 app/views/site/dashboard.html.erb:126:in `each' app/views/site/dashboard.html.erb:126 vendor/rails/actionpack/lib/action_view/helpers/capture_helper.rb:36:in `call' vendor/rails/actionpack/lib/action_view/helpers/capture_helper.rb:36:in `capture' vendor/rails/actionpack/lib/action_view/helpers/capture_helper.rb:129:in `with_output_buffer' vendor/rails/actionpack/lib/action_view/helpers/capture_helper.rb:36:in `capture' app/helpers/application_helper.rb:53:in `pull_box' app/views/site/dashboard.html.erb:108 ]]>

This error happens when visiting a user's dashboard - i.e. when logging in and the user has a repository favorited that does not exist anymore. Just remove it from the favorites table, and it'll work again.

undefined method `project_id' for nil:NilClass

NoMethodError (undefined method `project_id' for nil:NilClass):
  app/models/group.rb:85:in `all_related_project_ids'
  vendor/plugins/will_paginate/lib/will_paginate/finder.rb:168:in
`method_missing'
vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:369:in
`method_missing_without_paginate'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:215:in
`method_missing'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:215:in
`map'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:215:in
`send'
vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:215:in
`method_missing'
vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:369:in
`method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:168:in
`method_missing' app/models/group.rb:85:in `all_related_project_ids'
app/controllers/groups_controller.rb:35:in `show'

That error in your production.log means that the group/team which page you are visiting has (write) access to a repository that does not exist anymore. Delete that reference from the committerships table and all will be fine.

undefined method `team_repo?' for nil:NilClass


51:     
52: <% if event.has_commits? %> 53: <%= render_commit_details_for_push_event(event) -%> 54: <% end %> 55: <%# Inlining an additional div to contain the commits. TODO: This is in need of some love -%> 56: <% if event.action == Action::PUSH_SUMMARY -%> app/helpers/routing_helper.rb:52:in `repo_owner_path' app/helpers/event_rendering_helper.rb:375:in `render_commit_details_for_push_event' app/views/events/_event.html.erb:53 vendor/rails/actionpack/lib/action_view/renderable.rb:34:in `send' vendor/rails/actionpack/lib/action_view/renderable.rb:34:in `render' ]]>

Here we have references to a deleted repository in the events table. Look for target_type="Repository" and a target_id that points to a non-existing repository ID.

Written by Christian Weiske.

Comments? Please send an e-mail. Or Reply or Like.