-
-
Notifications
You must be signed in to change notification settings - Fork 895
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
fix #1980 user defined property metadata takes precedence #1997
Conversation
ping @oxan @bendavies |
I don't think this fixes #1994, as the |
Maybe it's better to leave the serializer factory alone and lower the priority of the annotation & extractor factories so that they run last (well, before the cache). Along with this PR to let them overwrite the present metadata, that should work fine. I checked and none of the existing factories seem to read from the metadata passed to them anyway (except to avoid overwriting), so I don't think it's a problem if they don't get the metadata configured by the user. (Actually, where I'm talking about the serializer factory, we should really think about all factories that set metadata based on heuristics. It's just that in my case the metadata I defined was overwritten by the serializer factory, but that could happen with others as well). |
Yes I think that this is safer :p. I added a commit that does this. |
Does Symfony guarantee an order of services with the same priority? Because the |
@@ -134,10 +134,6 @@ private function createMetadata(ApiProperty $annotation, PropertyMetadata $paren | |||
private function createWith(PropertyMetadata $propertyMetadata, array $property, $value): PropertyMetadata | |||
{ | |||
$getter = $property[0].ucfirst($property[1]); | |||
if (null !== $propertyMetadata->$getter()) { |
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 shouldn't be dropped. It's a BC break.
@@ -117,7 +117,7 @@ private function update(PropertyMetadata $propertyMetadata, array $metadata): Pr | |||
]; | |||
|
|||
foreach ($metadataAccessors as $metadataKey => $accessorPrefix) { | |||
if (null === $metadata[$metadataKey] || null !== $propertyMetadata->{$accessorPrefix.ucfirst($metadataKey)}()) { |
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.
Same here.
So I'd the factory can not be changed, the only possible fix is to alter the priority? |
Yes. It's cleaner anyway. And it allows anybody to customize the order (by changing priorities). |
But the factories are still weird in that some will overwrite, but some won't. Guess this can't be changed until 3.0? |
None should... |
I'll check tomorrow but I was under the impression that that wasn't the case. |
f5c0fca
to
f230bc4
Compare
I'm really unsure that changing priorities will be enough to fix this... |
Yeah, at least the |
It should be in the reverse order of service registration: |
So I should change |
that seems like it would be a BC break yes. seems like a catch 22 situation here to me. |
copying @Nek- nice image which shows the current state of things: |
Btw I can update it on demand. |
Anyway, if you guys need a resolution to this issue, you can always add your own To me this whole issue looks like a wontfix because I don't see any viable solution that doesn't break the current state of things... |
@bendavies There is no "ambiguous order" :) |
@teohhanhui it's not my image, but anyway, it's more a "non obvious" order. |
Is there any actual situation where autogenerated metadata overwiriting user-defined metadata is actually desired? Yes, preventing that is a BC break, but every bugfix is a BC break in a way. I can't think of any real-world situations where the current situation would be relied upon. The behaviour would only change in places where people purposefully have manually declared wrong metadata (in fact, |
@soyuka Yes, I'm currently using a custom metadata factory to be able to override the |
agree with @oxan really. |
I think a failing test case is needed to show how obviously wrong is "state of things". I'll do it next week if nobody is faster than me. But indeed the best solution is to drop the behavior of voting on null only for some of theses "voters". |
In the mean time we could always introduce a new annotation that overrides metadata (like the one from @oxan), feels dirty but at least it's non-breaking. |
22535af
to
deb3e07
Compare
@@ -117,7 +114,7 @@ private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $ | |||
$relatedClass = $type->isCollection() && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName(); | |||
|
|||
if (null === $relatedClass) { | |||
return $propertyMetadata; | |||
return $propertyMetadata->withReadableLink(true)->withWritableLink(true); |
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.
Kinda prevents the break, to me these should stay nullable
but it leads to bugs (essentially regarding docs
and context
- should I fix those there instead?).
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.
Yeah, I don't think this is correct, as this class is only supposed to fill in the metadata based on the Symfony Serializer mapping.
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'm totally 👍 to remove this but this has some impacts down the road.
Should we default these to true
or should we test for null || true
in the normalizers?
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.
Hmm... Now I see we were already doing this from before. 😱 I guess let's keep it then. Haha...
ping @oxan @Nek- @bendavies Could you guys give a shot at the latest version of this patch? Thanks! |
5114c1b
to
2f30e44
Compare
@dunglas wdyt? |
🚢 |
Should be merged in master, not in 2.3 because the priority change may break some apps. |
Change priority of user-defined metadata services to 20 User-defined metadata always overrides previous metadata
See issue.