appwrite/appwrite · error · Exception

ATTRIBUTE_VALUE_INVALID

ATTRIBUTE_VALUE_INVALID

Error message

The attribute value is invalid. Please check the type, range and value of the attribute.

What it means

Thrown by Databases/Attributes Integer Create when the supplied default value fails the Range validator built from min/max (ATTRIBUTE_VALUE_INVALID). The message 'The attribute value is invalid...' carries the validator description; here specifically it fires when a non-null default falls outside the requested min..max interval for the integer attribute being created.

Source

Thrown at src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php:94

            ->inject('dbForProject')
            ->inject('publisherForDatabase')
            ->inject('queueForEvents')
            ->inject('authorization')
            ->callback($this->action(...));
    }

    public function action(string $databaseId, string $collectionId, string $key, ?bool $required, ?int $min, ?int $max, ?int $default, bool $array, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void
    {
        $min ??= \PHP_INT_MIN;
        $max ??= \PHP_INT_MAX;

        if ($min > $max) {
            throw new Exception($this->getInvalidValueException(), 'Minimum value must be lesser than maximum value');
        }

        $validator = new Range($min, $max, Database::VAR_INTEGER);
        if (!\is_null($default) && !$validator->isValid($default)) {
            throw new Exception($this->getInvalidValueException(), $validator->getDescription());
        }

        // The 4 byte column only holds a range that fits INT32. min counts: a
        // column bounded below -2147483648 has to be able to store that value,
        // and with min left out the bound is PHP_INT_MIN.
        $size = $min >= -2147483648 && $max <= 2147483647 ? 4 : 8;

        $attribute = $this->createAttribute($databaseId, $collectionId, new Document([
            'key' => $key,
            'type' => Database::VAR_INTEGER,
            'size' => $size,
            'required' => $required,
            'default' => $default,
            'array' => $array,
            'format' => APP_DATABASE_ATTRIBUTE_INT_RANGE,
            'formatOptions' => ['min' => $min, 'max' => $max],
        ]), $response, $dbForProject, $publisherForDatabase, $queueForEvents, $authorization);

View on GitHub (pinned to ce3a85157f)

Solutions

  1. Adjust the default so it lies within [min,max], or widen min/max to include the desired default.
  2. Omit the default entirely (leave it null) and set values per-document instead.
  3. If you only need one bound, pass min or max and a default satisfying both implied bounds (unset bound becomes PHP_INT_MIN/PHP_INT_MAX).
  4. Double-check the request body: default must be an integer, not a string, and within range.

Example fix

// before
POST .../attributes/integer
{ "key": "age", "min": 0, "max": 120, "default": 150 } // 150 > max -> ATTRIBUTE_VALUE_INVALID
// after
{ "key": "age", "min": 0, "max": 120, "default": 30 }
Defensive patterns

Strategy: validation

Validate before calling

const valid = def === null || (min === null || def >= min) && (max === null || def <= max);
if (!valid) throw new Error(`default ${def} outside [${min ?? '-inf'}, ${max ?? '+inf'}]`);

Type guard

function isDefaultInRange(def, min, max) {
  return def === null || ((min === null || def >= min) && (max === null || def <= max));
}

Try / catch

try {
  await databases.createIntegerAttribute(dbId, colId, key, required, min, max, def);
} catch (e) {
  if (e.code === 'attribute_value_invalid') {
    // retry with corrected default or without default
  } else { throw e; }
}

Prevention

When it happens

Trigger: POST /v1/databases/{databaseId}/collections/{collectionId}/attributes/integer (or the tablesDB equivalent createIntegerColumn) with a default outside [min,max] — e.g. min=0, max=100, default=-5 or default=1000; also default=0 with min=1; or a default set while min/max were chosen such that it is out of range.

Common situations: Copy-pasting default values from a differently-bounded column; forgetting that omitting min/max defaults the range to PHP_INT_MIN..PHP_INT_MAX but supplying a partial range (only min or only max) and a default that violates the other bound; frontend sending default as string-typed coercion issues are caught earlier, this one is purely a range violation.

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 appwrite/appwrite@ce3a85157f (2026-09-08). Data as JSON: /api/errors/26f7868196158159. Report an issue: GitHub.