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

customer_id of NULL from a migration causes user preference error and no user listing anywhere #12

Closed
bingepiphany opened this issue Apr 20, 2010 · 5 comments

Comments

@bingepiphany
Copy link

When migrating from repo.clockingit.com version to the github version, there is a problem with the users. In the user tables in the DB, customer_id is set to NULL after the migration. This causes the following problems:

  • users are not listed anywhere.
  • if a user tries to access their preferences an exception occurs. Stack trace is below.

I fixed this by manually updating the DB table users: "update users set customer_id=1;" which put all the users in to the first client, which I wanted anyway. In general though, putting it either into an unknown client or the default client will still be a headache to the admin anyway, since they will have to manually move users from one client to another.


A ActionView::TemplateError occurred in users#edit_preferences:

undefined method `name' for nil:NilClass
On line #45 of app/views/users/_form.html.erb

42:   <%= check_box 'user', 'option_externalclients' %>
43:   <br/>
44: 
45:   <label for="user_auto_add"><%= _("Automatically add this user to tasks for %s", @user.customer.name) %></label>
46:   <%= check_box "user", "auto_add_to_customer_tasks" %>
47:   <br/>
48:  

app/views/users/_form.html.erb:45
app/views/users/_preferences.html.erb:13
app/views/users/edit_preferences.html.erb:5
app/views/users/edit_preferences.html.erb:4
passenger (2.2.11) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
passenger (2.2.11) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler'
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application'
passenger (2.2.11) lib/phusion_passenger/utils.rb:184:in `safe_fork'
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:163:in `start'
passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

Request:


Session:

  • session id: nil
  • data: nil

Environment:

  • DOCUMENT_ROOT : /repos/cit/public
  • HTTPS : on
  • HTTP_ACCEPT : text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
  • HTTP_ACCEPT_CHARSET : ISO-8859-1,utf-8;q=0.7,*;q=0.7
  • HTTP_ACCEPT_ENCODING : gzip,deflate
  • HTTP_ACCEPT_LANGUAGE : en-gb,en;q=0.5
  • HTTP_CONNECTION : keep-alive
  • HTTP_COOKIE : _session_id=88bcddf7e68b717b592c03c1907f3634; _jobsworth_session=6392eab7a49336f119db9de29a164bdc
  • HTTP_HOST : hostname
  • HTTP_KEEP_ALIVE : 115
  • HTTP_REFERER : http://hostname/activities/list
  • HTTP_USER_AGENT : Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
  • PATH_INFO : /users/edit_preferences
  • QUERY_STRING :
  • REMOTE_ADDR : xx.xx.xx.xx
  • REMOTE_PORT : 3173
  • REQUEST_METHOD : GET
  • REQUEST_URI : /users/edit_preferences
  • SCRIPT_NAME :
  • SERVER_ADDR : yy.yy.yy.yy
  • SERVER_ADMIN : webmaster@localhost
  • SERVER_NAME : hostname
  • SERVER_PORT : pp
  • SERVER_PROTOCOL : HTTP/1.1
  • SERVER_SOFTWARE : Apache/2.2.12 (Ubuntu)
  • SSL_TLS_SNI : hostname
  • _ : _
  • action_controller.request.path_parameters : actionedit_preferencescontrollerusers
  • action_controller.request.query_parameters :
  • action_controller.request.request_parameters:
  • action_controller.rescue.request : #ActionController::Request:0x7fa84d95ba80
  • action_controller.rescue.response : #ActionController::Response:0x7fa84d95b7b0
  • rack.errors : #IO:0x7fa85a5feab0
  • rack.input : #PhusionPassenger::Utils::RewindableInput:0x7fa84d95c778
  • rack.multiprocess : true
  • rack.multithread : false
  • rack.request.cookie_hash : _session_id88bcddf7e68b717b592c03c1907f3634_jobsworth_session6392eab7a49336f119db9de29a164bdc
  • rack.request.cookie_string : _session_id=88bcddf7e68b717b592c03c1907f3634; _jobsworth_session=6392eab7a49336f119db9de29a164bdc
  • rack.request.query_hash :
  • rack.request.query_string :
  • rack.run_once : false
  • rack.session : history/users/edit_preferences/activities/list/tasks/list/activities/listremember0filter_hidden0only_comments0user_id9filter_status0filter_priority-10hide_deferred0remember_untilMon Apr 19 02:59:05 UTC 2010last_task_id752filter_severity-10group_byshow_all_unread0filter_projecthide_dependencies0last_project_id0filter_userfilter_customersorticons0filter_milestone20filter_type-1flashcolors0
  • rack.session.options : cookie_onlytrueexpire_after3600key_jobsworth_sessionhttponlytruedomainid6392eab7a49336f119db9de29a164bdcpath/securefalse
  • rack.session.record : #ActiveRecord::SessionStore::Session:0x7fa84d954f50
  • rack.url_scheme : http
  • rack.version : 10
  • Process: 18946
  • Server : server

Backtrace:

On line #45 of app/views/users/_form.html.erb

  42:   <%= check_box 'user', 'option_externalclients' %>
  43:   <br/>
  44: 
  45:   <label for="user_auto_add"><%= _("Automatically add this user to tasks for %s", @user.customer.name) %></label>
  46:   <%= check_box "user", "auto_add_to_customer_tasks" %>
  47:   <br/>
  48:  

  app/views/users/_form.html.erb:45
  app/views/users/_preferences.html.erb:13
  app/views/users/edit_preferences.html.erb:5
  app/views/users/edit_preferences.html.erb:4
  passenger (2.2.11) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
  passenger (2.2.11) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
  passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler'
  passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application'
  passenger (2.2.11) lib/phusion_passenger/utils.rb:184:in `safe_fork'
  passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:163:in `start'
  passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
  passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
  passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
  passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
  passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
  passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
  passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
  passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
  passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
  passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
@oparoz
Copy link
Contributor

oparoz commented Jul 6, 2010

I did a clean install and had exactly the same problem with the first user, admin. Adding "1" to customer_id fixed a lot of things.

@ari
Copy link
Owner

ari commented Jul 6, 2010

OK, I'll see what I can do about this.

@mutalis
Copy link
Contributor

mutalis commented Jul 21, 2010

One way to fix it. Assign a user to the customer in setup.rb.

--- a/setup.rb
+++ b/setup.rb
@@ -218,6 +218,7 @@ puts "  Creating initial company..."
 if @company.save
   @customer = Customer.new
   @customer.name = @company.name
+  @user.customer = @customer

   @company.customers << @customer
   puts "  Creating initial user..."
@@ -237,6 +238,7 @@ else
       if @company.save
         @customer = Customer.new
         @customer.name = @company.name
+        @user.customer = @customer

         @company.customers << @customer
         puts "  Creating initial user..."

@ari
Copy link
Owner

ari commented Jul 23, 2010

Thanks very much for the patch. We'll certainly be doing that as well as adding a migration to fix existing data and adding mysql constraints to avoid breaking it again.

@ari
Copy link
Owner

ari commented Aug 5, 2010

Closing.

nasa42 pushed a commit that referenced this issue Apr 24, 2013
vshete pushed a commit to webstream-io/jobsworth that referenced this issue Dec 23, 2013
This issue was closed.
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

No branches or pull requests

4 participants