-
-
Notifications
You must be signed in to change notification settings - Fork 958
Fix nameConverter usage in Metadata #7667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.2
Are you sure you want to change the base?
Conversation
cdfd9e0 to
43cc9a8
Compare
| if (null !== $parameter->getProperty()) { | ||
| // Since the property is normalized I dunno where | ||
| // Notice that since NameConverter doesn't work for property path, it breaks nested property. | ||
| $propertyKey = $this->nameConverter?->denormalize($parameter->getProperty()) ?? $parameter->getProperty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related issue for the property path
symfony/symfony#63019
I wonder if ApiPlatform shouldnt decorate the nameconverter into a PropertyPathNameConverter and use it instead.
|
I feel like nameConverterInterface shouldn't be applied to filter since it's a Serializer tool. I would expect to work ; currently, only does And same, I would expect to word and I have to write This seems to be because of core/src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php Line 154 in c8493bb
|
|
|
||
| $propertyKey = $parameter->getProperty() ?? $parameter->getKey(); | ||
| if (null !== $parameter->getProperty()) { | ||
| // Since the property is normalized I dunno where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be normalized here
core/src/Doctrine/Common/Filter/OrderFilterTrait.php
Lines 51 to 53 in c8493bb
| $propertyName = $this->normalizePropertyName($property); | |
| $description[\sprintf('%s[%s]', $this->orderParameterName, $propertyName)] = [ | |
| 'property' => $propertyName, |
Or here
core/src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php
Line 263 in c8493bb
| $parameter = $parameter->withProperty($this->nameConverter->normalize($property)); |
|
I think we should just have another name converter that has nothing to do with the one for serialization, can this be fixed only by changing dependency injection on there? We should do the least transformations in the filters. |
Sure, I agree two different name converter should be use. I'm not even sure why one is used at the first place... Unless this is really useful in some case (which one ?), I would
Still, if the syntax |
334eb99 to
f281864
Compare
|
It's tricky because some tests seems to rely on this behavior:
If the property is normalized in ParameterResourceMetadataCollectionFactory I feel like while the Abstract legacy filters are correctly handling this case by denormalizing the property
All the new filters developed by @vinceAmstoutz are missing this transformation
Should the normalization be conditional ? |
|
I don't understand, if the property is
This makes this harder as then the responsability of converting is everywhere, we now have a way to cache these transformations lets use it.
yes and there's an important difference between a parameter key (and a property), if you use the placeholder |
8d978db to
8752bf5
Compare
Given the fact that's not how it works at the moment, I also have some trouble to understand what's expected and what's buggy. In my case I use the
I agree. |
| use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | ||
|
|
||
| abstract class AbstractFilter implements FilterInterface, PropertyAwareFilterInterface, ManagerRegistryAwareInterface | ||
| abstract class AbstractFilter implements FilterInterface, PropertyAwareFilterInterface, ManagerRegistryAwareInterface, NameConverterAwareInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is using this class ^^
We should really get rid of it it shows that the nameConverter responsibility is at the wrong place, a filter should only be like this:
public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
{
$parameter = $context['parameter'];
$value = $parameter->getValue();
$property = $parameter->getProperty();
$alias = $queryBuilder->getRootAliases()[0];
$parameterName = $queryNameGenerator->generateParameterName($property);
$queryBuilder
->{$context['whereClause'] ?? 'andWhere'}(\sprintf('%s.%s = :%s', $alias, $property, $parameterName))
->setParameter($parameterName, $value);
}
It should not have to transform property BUT if we change the AbstractFilter we break every filter that exists for 10 years.
| ContainerInterface $filterLocator, | ||
| ?ManagerRegistry $managerRegistry = null, | ||
| ?LoggerInterface $logger = null, | ||
| ?NameConverterInterface $nameConverter = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not include this at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this was needed for AbstractFilter only. Because some "non-deprecated but legacy" filters are still using it (like the OrderFilter).
But after so much debugging, I'll try without.
|
Maybe that we miss something, what is the value of |
8752bf5 to
38f4dbc
Compare
38f4dbc to
2723a53
Compare
This reverts commit 2723a53.
@soyuka Seems like the NameConverterAwareInterface is not needed anymore (?) All the tests added are green by removing the normalize call. There is only the Laravel one I'm not good with (I cannot even run the test locally). If you're ok checking it, that would be great ! |
See failure https://github.com/api-platform/core/actions/runs/20894952430/job/60032003544?pr=7667