Argument 1 passed to Michalsn\Uuid\Uuid::fromString() must be of the type string, null given, called in /castopod-host/vendor/michalsn/codeigniter4-uuid/src/UuidModel.php on line 381
This happens when trying to insert a record with a null value in a Uuid field that should be converted in bytes. Here is the line in question, in the doInsert method:
if (in_array($key, $this->uuidFields) && $this->uuidUseBytes === true)
{
$val = ($this->uuid->fromString($val))->getBytes(); // line 381, $val is null
}
Given that you may have a Uuid field with possible null values, there should be a check to prevent this from happening.
Possible solution
Add a condition to check that the field value is not null for insert and update:
Hey @michalsn!
I'm getting this error:
Argument 1 passed to Michalsn\Uuid\Uuid::fromString() must be of the type string, null given, called in /castopod-host/vendor/michalsn/codeigniter4-uuid/src/UuidModel.php on line 381
This happens when trying to insert a record with a
null
value in a Uuid field that should be converted in bytes. Here is the line in question, in thedoInsert
method:Given that you may have a Uuid field with possible null values, there should be a check to prevent this from happening.
Possible solution
Add a condition to check that the field value is not null for
insert
andupdate
: