Ruby on Rails SQLite3 :: BusyException: database is locked: INSERT INTO

1

Hello, I'm facing a problem with SQLite3. When I run the code:

user = SystemUser.new(email: "[email protected]", password: "marcos123")
user.profile = Profile.new(first_name: "Marcos")
user.save

Rails runs in SQLite:

(0.1ms)  begin transaction
  SystemUser Exists (2.7ms)  SELECT  1 AS one FROM "system_users" WHERE "system_users"."email" = ? LIMIT ?  [["email", "[email protected]"], ["LIMIT", 1]]
  SQL (7.1ms)  INSERT INTO "system_users" ("email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["email", "[email protected]"], ["encrypted_password", "$2a$11$Wl8mzOtFlD9RRCdAr38Ze.vYdrbrPRHkIEqutAsAyodQSDzihy35O"], ["created_at", "2017-11-12 23:27:23.270956"], ["updated_at", "2017-11-12 23:27:23.270956"]]
   (0.1ms)  begin transaction
  SQL (5188.0ms)  INSERT INTO "profiles" ("first_name", "created_at", "updated_at", "system_user_id") VALUES (?, ?, ?, ?)  [["first_name", "Marcos"], ["created_at", "2017-11-12 23:27:23.281227"], ["updated_at", "2017-11-12 23:27:23.281227"], ["system_user_id", 1]]
   (0.1ms)  rollback transaction
   (6.2ms)  rollback transaction
ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked: INSERT INTO "profiles" ("first_name", "created_at", "updated_at", "system_user_id") VALUES (?, ?, ?, ?)
        from (irb):3

It creates one transaction within another. I have read that SQLite blocks the file during a transaction. I looked for a resolution but I did not find it. If anyone has gone through this and can help me, I will be very grateful.

I have already tested with mysql and the code works

One solution found:

The project was in Rails 5.1.4 I downgraded the pro rails 5.1.0 project, the error persisted. After I created a project in Rails 5.0.6, the problem disappeared. So that's it, one solution is to use Rails 5.0.6

Here with 5.0.6

 (0.1ms)  begin transaction
  SQL (10.3ms)  INSERT INTO "users" ("email", "created_at", "updated_at") VALUES (?, ?, ?)  [["email", "[email protected]"], ["created_at", "2017-11-13 00:27:42.036072"], ["updated_at", "2017-11-13 00:27:42.036072"]]
  SQL (0.7ms)  INSERT INTO "profiles" ("first_name", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["first_name", "Marcos"], ["user_id", 1], ["created_at", "2017-11-13 00:27:42.122640"], ["updated_at", "2017-11-13 00:27:42.122640"]]
   (5.0ms)  commit transaction
=> true
    
asked by anonymous 13.11.2017 / 00:33

1 answer

0

Continuing the logbook: The problem is in the gem 'apartment'. This problem happens in models that are in config.excluded_models

    
13.11.2017 / 02:19