Skip to content

Cannot findBy with a string on a DateTime field since 2.20.7 #12339

@lou-perret

Description

@lou-perret

Bug Report

Q A
Version 2.20.7 (still happening in 2.20.9)
Previous Version if the bug is a regression 2.20.6

Summary

Hello !

Since the 2.20.7 update, it looks like we cannot do a "findBy" on a Doctrine\DBAL\Types\Types\Types::TIME_IMMUTABLE (or DATE_MUTABLE) field with strings anymore

Replacing the strings with \DateTimeImmutable does the trick

Current behavior

Create an entity with

	#[ORM\Column(type: Types::DATE_IMMUTABLE)]
	private ?\DateTimeImmutable $date = null;

Use it like this

$this->em->getRepository(MyEntity::class)->findBy(['date' => '2025-02-04']);
Could not convert PHP value '2025-02-04' to type date_immutable. Expected one of the following types: null, DateTimeImmutable

 trace: {
        /vendor/doctrine/dbal/src/Types/ConversionException.php:78 { …}
        /vendor/doctrine/dbal/src/Types/DateImmutableType.php:41 { …}
        /vendor/doctrine/dbal/src/Connection.php:1887 { …}
        /vendor/doctrine/dbal/src/Connection.php:1828 { …}
        /vendor/doctrine/dbal/src/Connection.php:1102 { …}
        /vendor/doctrine/orm/src/Persisters/Entity/BasicEntityPersister.php:995 { …}
        /vendor/doctrine/orm/src/EntityRepository.php:224 { …}

Expected behavior

I should get an array with every MyEntity with the date of 2025-02-04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions