instructure/canvas-lms · error · ArgumentError

PartitionManager can only work on models that are…

Error message

PartitionManager can only work on models that are Partitioned.
See CanvasPartman::Concerns::Partitioned.

What it means

CanvasPartman::PartitionManager.create builds a strategy object (Dynamic or Static) to manage partitions of a model. It only accepts model classes that include CanvasPartman::Concerns::Partitioned, because the manager relies on partitioning_strategy and related APIs. Passing a plain ActiveRecord class raises ArgumentError.

Solutions

  1. Add `include CanvasPartman::Concerns::Partitioned` to the model class
  2. Verify you are passing the model class itself, not an instance or unrelated class
  3. Ensure the model's migration creates the partitioned table matching its strategy

Example fix

// before
class QueuedMessage < ActiveRecord::Base; end
PartitionManager.create(QueuedMessage)
// after
class QueuedMessage < ActiveRecord::Base
  include CanvasPartman::Concerns::Partitioned
end
PartitionManager.create(QueuedMessage)
Defensive patterns

Strategy: type-guard

Validate before calling

raise ArgumentError unless MyModel.include?(CanvasPartman::Concerns::Partitioned)

Type guard

def partitioned_model?(klass) = klass.is_a?(Class) && klass < CanvasPartman::Concerns::Partitioned

Prevention

When it happens

Trigger: Calling CanvasPartman::PartitionManager.create(SomeModel) where SomeModel does not `include CanvasPartman::Concerns::Partitioned` (or the mixin is included after the call).

Common situations: Forgetting the `include CanvasPartman::Concerns::Partitioned` line when adding a new partitioned table; using the manager against a shared base class; copy-pasting PartitionManager usage from another model.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/be700edf538573d0. Report an issue: GitHub.

Appendix: source

Thrown at gems/canvas_partman/lib/canvas_partman/partition_manager.rb:29

#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

require "canvas_partman/partition_manager/by_date"
require "canvas_partman/partition_manager/by_id"
require "active_record/pg_extensions"

module CanvasPartman
  class PartitionManager
    class << self
      def create(base_class)
        unless base_class < Concerns::Partitioned
          raise ArgumentError, <<~TEXT
            PartitionManager can only work on models that are Partitioned.
            See CanvasPartman::Concerns::Partitioned.
          TEXT
        end

        const_get(base_class.partitioning_strategy.to_s.classify).new(base_class)
      end
    end

    attr_reader :base_class

    # Create partitions to hold existing data in a non-partitioned
    # table, and n future partitions
    #
    # @param [Integer] advance
    #   The number of partitions to create in advance
    def create_initial_partitions(_advance = 1)
      raise NotImplementedError

View on GitHub (pinned to 1c9f0bb801)