Skip to content

The db:purge rake task emits warnings and doesn't actually work #153

@flavorjones

Description

@flavorjones

The db:purge rake task, which is run before the test suite, will emit a harmless but annoying NoTenantError:

ActiveRecord::Tenanted::NoTenantError: Cannot use an untenanted ActiveRecord::Base connection. If you have a model that inherits directly from ActiveRecord::Base, make sure to use 'subtenant_of'. In development, you may see this error if constant reloading is not being done properly. (ActiveRecord::Tenanted::NoTenantError)

This is happening because this task doesn't run with a temporary connection pool, so this needs to be fixed upstream in Rails. See some history and context at rails/rails#46270.

My first (wrong) attempt to fix it was rails/rails#54536. In that issue's thread, we established that the correct fix is to continuing the work started in rails/rails@c74b290 which (according to the commit log message) is aimed at passing a class into the adapter-specific database task classes:

  • ActiveRecord::Tasks::MySQLDatabaseTasks
  • ActiveRecord::Tasks::SQLiteDatabaseTasks
  • ActiveRecord::Tasks::PostgreSQLDatabaseTasks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions