Entity Validator failing Integer for not being integer I have a custom entity with an integer field with the following baseFieldDefinition:

    $fields['permission_level'] = BaseFieldDefinition::create('integer')
    -&gt;setLabel(t("Permission Level"))
    -&gt;setDescription(t("Sets amount of permissions owner has"))
     -&gt;addConstraint('Range', ['min' =&gt; 0])
    -&gt;setDefaultValue(0)
    -&gt;setDisplayOptions('form', [
      'type' =&gt; 'number'
    ]);


because of the -&gt;addConstraint('Range', ['min' =&gt; 0]), drupal throws an error anytime I try to create an entity through either the drupal generate:entity:content generated boilerplate form or json:api post requests.

I have used Xdebug to narrow the issue to the constraint validator range.
Something is passing a FieldListItem object instead of an integer to this constraint validator causing it to fail because its not an integer. The weird thing is that inside the FieldListItem object is the integer I input.

Why is drupal passing a FieldListItem object instead of an Integer?
You can add constraints to entities, fields or properties. You get then an entity, field object (FieldItemList) or a value to validate. So if you want to check the field value use FieldConfigInterface::addPropertyConstraints:

-&gt;addPropertyConstraints('value', ['Range'=&gt; ['min' =&gt; 0]])