Skip to content

Bad query parameters when the identifier is a Doctrine Type in Doctrine ItemDataProvider:getItem #1167

@magarzon

Description

@magarzon

Hi.

I found an issue in doctrine ItemDataProvider introduced in v2.0.8.

In the doctrine ItemDataProvider, when is getting an item, is building a query using the identifiers in the request.

To get the identifiers, first it normalizes them, because can be another than id and even can be two fields

This normalization is performed now by a trait, IdentifierManagerTrait. So, in this line: https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Util/IdentifierManagerTrait.php#L76 is converting the value of the identifier, if it has a Doctrine type, to its PHP value.

I don't know if this it's needed, because eventually this value is used to query the database, and it should be the database value for that type, not the PHP value, that can be even an object.

If the reason to add this is some kind of conversion of the input to the PHP value, there is another step missing: In the addWhereForIdentifiers method in ItemDataProvider, when is setting the parameter in the query builder, it should check again the type (as it's done in the trait), and add it as the third parameter:
$queryBuilder->setParameter($placeholder, $value, $type);

If you don't do that, the default type is string, and then doctrine doesn't call Type::convertToDatabaseValue and instead of the right value for that parameter/type, the value could be (as in my case, that is an object), the classname.

So, or either remove the conversion in the trait if it's not really needed, or the type must be added as I explained.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions