mongodb/mongoid · error · Mongoid::Errors::UnknownAttribute

Attempted to set a value for '%{name}' which is not allowed

Error message

Attempted to set a value for '%{name}' which is not allowed on the model %{klass}.

What it means

Error "Attempted to set a value for '%{name}' which is not allowed on the model %{klass}." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/attributes/processing.rb:120

      # @return [ Hash ] The pending nested attributes in key/value pairs.
      def pending_nested
        @pending_nested ||= {}
      end

      # If the attribute is dynamic, add a field for it with a type of object
      # and then either way set the value.
      #
      # @example Process the attribute.
      #   document.process_attribute(name, value)
      #
      # @param [ Symbol ] name The name of the field.
      # @param [ Object ] value The value of the field.
      def process_attribute(name, value)
        if !respond_to?("#{name}=", true) && (store_as = aliased_fields.invert[name.to_s])
          name = store_as
        end
        responds = respond_to?("#{name}=", true)
        raise Errors::UnknownAttribute.new(self.class, name) unless responds

        send("#{name}=", value)
      end

      # Process all the pending nested attributes that needed to wait until
      # ids were set to fire off.
      #
      # @example Process the nested attributes.
      #   document.process_nested
      def process_nested
        pending_nested.each_pair do |name, value|
          send("#{name}=", value)
        end
      end

      # Process all the pending items, then clear them out.
      #
      # @example Process the pending items.

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/attributes/processing.rb:120 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/b89bf408e57e38cb. Report an issue: GitHub.