This value should be of the correct primitive type.

Created on 3 December 2024, 3 months ago

Problem/Motivation

I've added a field to hold perceptual hash value that needs unsigned bigint. But when I save a value like 12422829485478800581 the entity form fails validation with "This value should be of the correct primitive type."
The value is failing at /web/core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidator.php validate()

if ($typed_data instanceof IntegerInterface && filter_var($value, FILTER_VALIDATE_INT) === FALSE) {
      $valid = FALSE;
}

I can save the value into MySQL if I comment out this validation test.

Perhaps Drupal core assumes bigint is signed?

Running on Drupal 10.3.10, PHP 8.1, 64 bit PHP, PHP_INT_SIZE=8.

Steps to reproduce

Add an unsigned bigint field to an entity (e.g. media). Try and save the form with the value. 12422829485478800581.

Proposed resolution

Need to understand whether bigint module can handle this, or if it is a Drupal core issue.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇳🇿New Zealand jonathan_hunt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jonathan_hunt
  • 🇧🇪Belgium tim-diels Belgium 🇧🇪

    I'm not sure what the max allowed value should or could be. If i'm searching I can find an issue with MySQL https://bugs.mysql.com/bug.php?id=103992

    The number 9223372036854775807 seems acceptable by Drupal and 9223372036854775808 not. So it does seem its the function FILTER_VALIDATE_INT that messes this up. But I don't want to remove this one. Is there another function maybe we can use to validate if this is a unsigned bigint?

  • 🇬🇧United Kingdom hughworm

    I have this issue and I'm looking for an answer also for perceptual hash values. I'm finding it's silently failing on save() - a real value gets saved 9223372036854775807. Even if I put the correct value in the DB the value is read as 9223372036854775807.

    @jonathan_hunt did you find an answer?

  • 🇳🇿New Zealand jonathan_hunt

    @hughworm No I had to put this work to one side, so haven't progressed it. I'd like to make progress eventually but it won't be for a little while. I'd like to see a way for Drupal to cope with unsigned bigint.

Production build 0.71.5 2024