instructure/canvas-lms · error · ArgumentError

Partition resolution failure!!! Expected "#

Error message

Partition resolution failure!!!
Expected "#{partitioning_field}" attribute to be present in set and
have a value, but was or did not:

#{attributes}

What it means

CanvasPartman partitions tables by a partitioning_field (e.g. 'created_at' or an id column). infer_partition_table_name scans the attributes hash for that key to compute which partition table to target. If the key is absent or its value is nil, no partition can be determined, so ArgumentError is raised with the offending attributes dumped.

Solutions

  1. Ensure every attribute hash passed to partitioned-model creation includes the partitioning field with a non-nil value
  2. Set a default for the partitioning column in your model/callbacks before persisting
  3. Check which caller passed an incomplete attributes set (message prints the full hash)
  4. Rescue ArgumentError around CanvasPartman calls if partial batches are expected

Example fix

// before
partman.create(QueuedMessage, body: 'hi')
// after
partman.create(QueuedMessage, created_at: Time.now.utc, body: 'hi')
Defensive patterns

Strategy: validation

Validate before calling

attrs.each { |a| raise ArgumentError, "missing #{field}" unless a[field].present? }

Type guard

def partition_ready?(attrs, field) = attrs.key?(field.to_s) && !attrs[field.to_s].nil?

Prevention

When it happens

Trigger: Calling attrs_in_partition_groups or arel_table_from_key_values (e.g. via CanvasPartman#create/dynamic queries) with an attributes hash that omits the partitioning field or sets it to nil.

Common situations: Bulk inserts where only some attribute hashes include the partition key; mass-assigning records without timestamps; renaming the partitioning column without updating callers.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at gems/canvas_partman/lib/canvas_partman/concerns/partitioned.rb:170

        @arel_tables[partition_table_name] ||= Arel::Table.new(partition_table_name, klass: self)
      end

      # @internal
      #
      # Come up with the table name for the partition the record with the given
      # attribute pairs should be placed in.
      #
      # @param [Array<Array<String, Mixed>>] attributes
      #  Attribute pairs the model is being created/updated with. You can use
      #  these to infer the partition name, e.g, based on :created_at.
      #
      # @return [String]
      #  The table name for the partition.
      def infer_partition_table_name(attributes)
        attr = attributes.detect { |(k, _v)| (k.is_a?(String) ? k : k.name) == partitioning_field }

        if attr.nil? || attr[1].nil?
          raise ArgumentError, <<~TEXT
            Partition resolution failure!!!
            Expected "#{partitioning_field}" attribute to be present in set and
            have a value, but was or did not:

            #{attributes}
          TEXT
        end

        if partitioning_strategy == :by_date
          date = attr[1].is_a?(ActiveModel::Attribute) ? attr[1].value : attr[1]
          date = date.utc if ActiveRecord.default_timezone == :utc

          case partitioning_interval
          when :weeks
            date = date.to_date
            [table_name, date.cwyear, ("%02d" % date.cweek)].join("_")
          when :months
            [table_name, date.year, date.month].join("_")

View on GitHub (pinned to 1c9f0bb801)