Updated: Comment #N
Problem/Motivation
Noticed a number of problems in hal serialization while working on #2002138: Use an adapter for supporting typed data on ContentEntities.
Moving this to a separate issue to work on this in parallel, the overlap with that issue is the getFields()/getProperties() rename that is happening there and we can even switch to use the iterator here so that it won't have to be changed again.
Known issues:
1. Config entities are incorrectly exported, they're added as embedded resources, but we currently can not serialize/expose them, so that seems wrong.
2. There's a bogus getName() == 'id' check to exclude the entity ID, that should use the entity key instead. There's also the question of the revision_id, which we should then exclude as well.
Proposed resolution
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | interdiff-2219795-7.txt | 1.38 KB | damiankloip |
| #7 | 2219795-7.patch | 22.52 KB | damiankloip |
Comments
Comment #1
berdirSeparated the changes there.
To test this, I added a test that normalizes a node and then denormalizes it and compares the result, the same for a term.
Also noticed that the node author was broken because it's a base field and RelationLinkManager only supports configurable fields.
Term is still broken due #2135573: Hal Entity Normalizer assumes bundle key is always 'type', which currently doesn't have test coverage, going to suggest to merge the issues over there.
Also found #2143089: Clean up normalizer parameter and variable names to use "field_items" consistently etc, which is related as well and contains some more cleanup.
No idea were to stop.. for every thing that I fix I'm finding more stuff that's strange/broken. RelationLinkManager claims that getRelationInternalIds() implements the interface but doesn't, the cache logic is bad as every call results in a new cache get() (new database query) and the set writes and then reads it out again. And the only thing that we're caching is an array of strings and a simple array, which is pretty easy and fast to build? Fetching that from the database every time it is requested is probably slower and uses more memory than just building it or trying to validate the relation URI on demand... Also, we're defining relations for every field (now every base field too) without checking if they're even a reference field... :(
Comment #4
damiankloip commentedok, merged in changes from #2135573: Hal Entity Normalizer assumes bundle key is always 'type' to berdir's patch here. Let's see how this gets on. I think it should pass ok actually.
Comment #5
klausiThe comment still speaks of properties, that should be changed to fields as well?
Any reason why the new test is not a PHPUnit test? Maybe it makes sense to have this kind of integration test, so I'm just asking. Otherwise looks reasonable to me.
Comment #6
berdirThe entity system can't be properly unit tested yet, too much going on there.
This is meant to be an integration test, to make sure that we can handle an actual real-world entity. Since this code was written, we introduced support for config entity references and made the uid a reference field, both resulted in bugs here. I'd like to catch bugs in case we make further changes there...
The manual creation of the serialization classes is already too unittest-y for my taste for this test, as leaving out the services.yml definition for example would still result in a green patch but wouldn't work for a real case :)
Comments should be fixed, yes.
Comment #7
damiankloip commentedHow about that?
We can discuss changing the NormalizerTestBase class in a follow up. That should be be the concern of this issue.
Comment #8
klausiLooks good after reviewing the patch one more time.
Comment #9
damiankloip commentedGreat. Thanks!
Comment #11
damiankloip commented7: 2219795-7.patch queued for re-testing.
Comment #12
berdirGreen again, random fail? Back to RTBC.
Comment #13
fagoThis looks like a great clean-up! Here some comments:
Sounds like this would be better handled in supportsNormalization() ? Probably not a big deal anyway.
I'm not 100% sure one can rely on all numeric deltas being there, i.e. count == index of next item. As alternative - it supports the [] syntax, but then you won't get back the item. So when this is problematic (nothing introduced here), does that mean we should introduce a public appendItem() which returns the new item?
Wondering how that introduction is related or not?
uhm - great to see this fixed.
Comment #14
berdir1. Yeah, that's exactly what I tried to do initially in of the earlier patches in the adapter issue. Took a lengthy debugging session to figure out that the Serializer class has a static cache of the supports information, based on the class/format. But only when actually doing the normalization and not when checking if there is a supporter normalizer o.0 So the supports methods is fairly useless and misleading as you can't have any dynamic checks. The whole class is quite a mess and I did open a pull request to clean things up a bit: https://github.com/symfony/symfony/pull/10457.
2. Not sure, but I'm not making anything worse here :)
3. It's needed to be able to look up config entities based on their ID. Otherwise, it just ignores the value, even if it is already in the required format. I think the whole entity resolver stuff is a bit overarchitected and we could also directly check this in the normalizer class but I'm just following the existing flow.
Comment #15
damiankloip commentedYeah :/ We would have to get around this by just having two normalizers. with something like:
So not sure this IS really worth it tbh. We don't gain much, and it will just be slightly slower.
Comment #16
fagoThanks for the clarifications! ad #15: Yeah, and as berdir pointed out it wouldn't work even!
So this is great as it is :-)
Comment #17
berdirComment #18
alexpottCommitted and pushed to 8.x
Removed these unused uses during commit.
Comment #21
effulgentsia commentedThe issue summary says:
And the patch committed here does that, but I don't see any comments explaining why. #2304849: Stop excluding local ID and revision fields from HAL output proposes to stop excluding revision ID. Please comment there with objections to that if you have any.