API Platform version(s) affected: 2.5.5
Description
ORM Search Filter on Date field with exact match fails since v2.5.5. I have many entities with a Date fields that always contain the 1st day of every month. I have historically been doing exact ORM search filters on these fields in my API. I can confirm that as of v2.5.4 the filters work fine, but after updating to v2.5.5 I get the following error when passing a value such as "2017-01-10" in a Date field:
Could not convert PHP value '2017-01-10' of type 'string' to type 'date'. Expected one of the following types: null, DateTime
How to reproduce
Search service YML:
fubar.search_filter: parent: 'api_platform.doctrine.orm.search_filter' arguments: [ { month: 'exact' } ] tags: [ { name: 'api_platform.filter', id: 'fubar.search' } ]
Entity class:
class Fubar { /** * @var \Date The month * * @ORM\Column(type="date") * @Assert\Date */ private $month; }
Possible Solution
I believe the issue is from the fact that all data used in the API search filter originates as text - which can only evaluate to simple data types without special conversion (which would be required for Date/DateTime objects). Since https://github.com/api-platform/core/pull/3331/commits/57ec463c8259fddc7505eae73d284406dfee998d the queryBuilder parameter sets the expected dataType based on the doctrine field types - which throws an error when doing an exact filter on a date field.
API Platform version(s) affected: 2.5.5
Description
ORM Search Filter on Date field with exact match fails since v2.5.5. I have many entities with a Date fields that always contain the 1st day of every month. I have historically been doing exact ORM search filters on these fields in my API. I can confirm that as of v2.5.4 the filters work fine, but after updating to v2.5.5 I get the following error when passing a value such as "2017-01-10" in a Date field:
Could not convert PHP value '2017-01-10' of type 'string' to type 'date'. Expected one of the following types: null, DateTimeHow to reproduce
Search service YML:
fubar.search_filter: parent: 'api_platform.doctrine.orm.search_filter' arguments: [ { month: 'exact' } ] tags: [ { name: 'api_platform.filter', id: 'fubar.search' } ]Entity class:
class Fubar { /** * @var \Date The month * * @ORM\Column(type="date") * @Assert\Date */ private $month; }Possible Solution
I believe the issue is from the fact that all data used in the API search filter originates as text - which can only evaluate to simple data types without special conversion (which would be required for Date/DateTime objects). Since https://github.com/api-platform/core/pull/3331/commits/57ec463c8259fddc7505eae73d284406dfee998d the queryBuilder parameter sets the expected dataType based on the doctrine field types - which throws an error when doing an exact filter on a date field.