manyfold3d / manyfold

A self-hosted digital asset manager for 3d print files.
https://manyfold.app
MIT License
772 stars 48 forks source link

500 error when starting for first time #2157

Closed matthewbadeau closed 5 months ago

matthewbadeau commented 5 months ago

Describe the bug Upon first launching the app, a 500 error is presented.

To Reproduce Steps to reproduce the behavior:

  1. Launch Rails console and delete all users (simulating launching for the first time)
  2. Start dev environment: bin/dev
  3. Browse to http://127.0.0.1:5000/
  4. 500 error

Expected behavior The application should create the initial user upon startup.

Screenshots

21:00:46 rails.1     |   ActiveRecord::SchemaMigration Pluck (0.2ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
21:00:46 rails.1     |    (0.2ms)  SELECT "flipper_features"."key" AS feature_key, "flipper_gates"."key", "flipper_gates"."value" FROM "flipper_features" LEFT OUTER JOIN "flipper_gates" ON "flipper_features"."key" = "flipper_gates"."feature_key"
21:00:46 rails.1     |   User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 1], ["LIMIT", 1]]
21:00:46 rails.1     | method=GET path=/ format=html controller=HomeController action=index status=0 allocations=4707 duration=18.87 view=0.00 db=0.63
21:00:46 rails.1     |    (0.2ms)  SELECT "flipper_features"."key" AS feature_key, "flipper_gates"."key", "flipper_gates"."value" FROM "flipper_features" LEFT OUTER JOIN "flipper_gates" ON "flipper_features"."key" = "flipper_gates"."feature_key"
21:00:46 rails.1     | 2024-05-10T12:00:46.863Z pid=19717 tid=391 INFO: Sidekiq 7.2.4 connecting to Redis with options {:size=>10, :pool_name=>"internal", :url=>nil}
21:00:46 rails.1     |   User Exists? (0.2ms)  SELECT 1 AS one FROM "users" INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON "roles"."id" = "users_roles"."role_id" WHERE (((roles.name = 'administrator') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) LIMIT ?  [["LIMIT", 1]]
21:00:46 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:34:in `auto_login_single_user'
21:00:47 rails.1     |   TRANSACTION (0.1ms)  begin transaction
21:00:47 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     |   User Exists? (0.2ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ?  [["email", "root@localhost"], ["LIMIT", 1]]
21:00:47 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     |   User Exists? (0.1ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."username") = LOWER(?) LIMIT ?  [["username", "1e92c936"], ["LIMIT", 1]]
21:00:47 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     |   User Exists? (0.1ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER(?) LIMIT ?  [["email", "root@localhost"], ["LIMIT", 1]]
21:00:47 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     |   User Create (0.4ms)  INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at", "username", "pagination_settings", "renderer_settings", "tag_cloud_settings", "problem_settings", "file_list_settings", "reset_password_token", "remember_created_at", "reset_password_sent_at", "interface_language") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["email", "root@localhost"], ["encrypted_password", "$2a$12$cQWDlMlgJpr3k9AvAkCPNeRhS58eNEpfuDLLWatY8NWQ29jwwl9p."], ["created_at", "2024-05-10 12:00:47.113473"], ["updated_at", "2024-05-10 12:00:47.113473"], ["username", "1e92c936"], ["pagination_settings", "{\"models\":true,\"creators\":true,\"collections\":true,\"per_page\":12}"], ["renderer_settings", "{\"grid_width\":200,\"grid_depth\":200}"], ["tag_cloud_settings", "{\"threshold\":0,\"heatmap\":true,\"keypair\":true,\"sorting\":\"frequency\",\"hide_unrelated\":true}"], ["problem_settings", "{\"missing\":\"danger\",\"empty\":\"info\",\"nesting\":\"warning\",\"inefficient\":\"info\",\"duplicate\":\"warning\",\"no_image\":\"silent\",\"no_3d_model\":\"silent\",\"non_manifold\":\"warning\",\"inside_out\":\"warning\"}"], ["file_list_settings", "{\"hide_presupported_versions\":true}"], ["reset_password_token", "first_use"], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["interface_language", nil]]
21:00:47 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     |   TRANSACTION (0.3ms)  rollback transaction
21:00:47 rails.1     |   ↳ app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     | method=GET path=/users/sign_in format=html controller=Users::SessionsController action=new status=500 allocations=20377 duration=262.79 view=0.00 db=1.24
21:00:47 rails.1     |   
21:00:47 rails.1     | ActiveRecord::StrictLoadingViolationError (`User` is marked for strict_loading. The Role association named `:roles` cannot be lazily loaded.):
21:00:47 rails.1     |   
21:00:47 rails.1     | app/models/user.rb:58:in `assign_default_role'
21:00:47 rails.1     | app/controllers/users/sessions_controller.rb:45:in `create_admin_user'
21:00:47 rails.1     | app/controllers/users/sessions_controller.rb:34:in `auto_login_single_user'
21:00:47 rails.1     | app/controllers/application_controller.rb:42:in `switch_locale'

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

I encountered this problem launching in dev. I tested on the docker nightly but I did not see this issue.

Floppy commented 5 months ago

Aha. This is a dev-only problem, and it's because I half-did some strict loading code a while back and never finished it. I've got a change on my local checkout that turns that off again. I should commit it. Bear with me.

Floppy commented 5 months ago

Basically the line config.active_record.strict_loading_by_default = true in development.rb just needs removing or commenting out. I was trying to force myself to fix the N+1 problems, so I left it in, but I just worked around myself instead 😆 .

matthewbadeau commented 5 months ago

Well that did it, thank you. I'll close the PR out and we can probably close this issue for now.

Floppy commented 5 months ago

I'll do a PR in a moment to remove the code which will close this. Sorry about that. There's not normally anyone using the code except me 😁