Closed (fixed)
Project:
Drupal core
Version:
8.4.x-dev
Component:
hal.module
Priority:
Minor
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 Mar 2017 at 16:38 UTC
Updated:
13 Sep 2023 at 23:38 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
br0kenAlso, some part of
halmodule is already uses this behavior. See\Drupal\hal\Normalizer\FieldNormalizer.Comment #3
br0kenComment #4
br0kenComment #5
l0keAdded test to demonstrate that
supportsDenormalization()method override was redundant and it's removal will not break anything.Also noticed that
$supportedInterfaceOrClassproperty can be an array for example:Drupal\serialization\NormalizerContentEntityNormalizerIn this case implementation of
\Drupal\hal\Normalizer\NormalizerBase::supportsDenormalization()will throw\RuntimeException Array to string conversionon this lineUploading a patch and let's wait until tests will pass.
Comment #6
br0kenThe patch above is just demonstrating that removed logic has not worked in a different way. Great work, @l0ke! Thanks. If tests becomes passed then it looks like changes are safe to be committed.
Comment #7
wim leersThis has been bothering me for a long time too, but it was never a big enough deal to create this issue. Thanks!
SupportDenormalizationUnitTestis kind of a strange test. Possibly we already have enough functional test coverage that we don't need this unit test that is comparing "old code" with "new code" and asserting the results are the same. This test makes sense right now, but it won't anymore after this is committed.I'll let a core committer decide.
Just two nits:
Needs
\nin between. After that's fixed, this is RTBC.Comment #8
br0ken@Wim Leers, patch in #5 named as 2863778-5-do-not-commit.patch and created only for demonstration purposes (what you've mentioned in your comment). We discussed this with @l0ke and he has created the patch only to show to the committers/reviewers that removed logic was doing completely the same. (that's simplifies the review and testing).
According to above, coding standards problems should be ignored for patch #5 since it's have only demonstration character.
Comment #9
wim leersAhhhh, right! Great :)
Can you then please repulsed #2? Core committers expect the last patch to be the patch to commit.
Comment #10
br0kenComment #11
alexpottNeed a new line here.
Is this change covered by a test anywhere?
Comment #12
alexpott@BR0kEN also - just so you know - hiding the files doesn't affect the RTBC retest.
Comment #13
br0ken@alexpott, I hiding the files because they are auxiliary.
Comment #14
br0kenThe
formatproperty is used only by two normalizers in core:\Drupal\hal\Normalizer\FieldNormalizerand\Drupal\hal\Normalizer\NormalizerBase. I'm proposing to change forempty()because there's no sense to convert "empty" data to an array.Comment #15
br0kenComment #16
br0kenBut let's allow the next:
in_array('', ['']).Comment #17
br0ken@alexpott, regarding your 4 point. I can't realize where you found
in_array()with three arguments called.Comment #18
wim leersComment #19
alexpott@BR0kEN - it's the lack of the third argument and it not being TRUE that scares me. Pretty much people always want
in_array($needle, $haystack, TRUE)and notin_array($needle, $haystack)- see https://3v4l.org/sr29YComment #20
br0ken@alexpott, ah, that's what you meant - got it now. Are you proposing to change this here, in scope of this issue, or leave as is?
Comment #21
alexpott@BR0kEN not in scope because as far as we know it is not causing issues but it'd be great if someone could open an issue about it.
Comment #22
br0kenI'll do, @alexpott. Especially because I'm really close to this pieces of core right now.
UPD: #2864495: Use strict mode for "in_array()" functions in "\Drupal\serialization\Normalizer\NormalizerBase" for verifying supported types for (de-)normalization
Comment #23
alexpottSorry I just noticed this rename. We shouldn't rename a property on a base class. This is API. Things are meant to inherit from this class - it's abstract! Or at least it we do this we need to implement a magic __get and __set for the property "formats" - which gets complex because the original scope of the property is protected.
Maybe the thing to do is make the base class use either $format or $formats? And deprecate $formats. Tricky. BC is hard.
Comment #24
catchThat seems right here. Use $formats if it's set, but trigger_error() with a deprecation notice, use $format otherwise with no deprecation notice. Then a subclass with no changes continues to work the same way but gets the notice.
I thought about doing it the other way, but since the property is already set there doesn't seem a way around that.
Comment #25
br0ken@alexpott, are you worrying about custom implementations? If yes, then makes sense.
Comment #26
xjmFor reference, here is the handbook page on how to add the deprecation: https://www.drupal.org/core/deprecation
And in general, yes, we do have to at least consider the impact on custom implementations.
Comment #27
br0ken@xjm I haven't found anything regarding class properties. What is the correct approach is this case?
Comment #28
wim leersNote that the next steps are clearly described in #24.
Comment #29
wim leersThis blocks #2856110: [PP-1] Expose entity validation errors in a machine readable REST API: .
Comment #30
wim leersComment #31
dawehnerThere we go.
Comment #32
wim leersThanks!
Using either
$this->formator$this->formatsis allowed.Therefore this should be
And the
$this->formathere should be either$this->formator$this->formats, right now this is still breaking BC.P.S.: also should use strict comparison.
Comment #33
dawehnerWell, the parent is using the non strict comparison already, but yeah meh.
Oh njce point! I improved the readability of the logic a bit.
Comment #35
wim leersI don't understand any of the changes in #33.
Also, yay, #31 failed! Seems like we have some test coverage for this that is now failing due to the bug I pointed out in #32.
Comment #36
dawehnerCan you clarify what you don't understand? The only logic I applied on top of your comment is:
(!$ && !b) == !($a || b)Comment #37
wim leersOh, hah, I misread! That part now makes sense. But this part still does not:
How is this supposed to work, if you used
class::$format?Oh… you kept the rename. We shouldn't do that, see #23. That's what I was getting at in #32.2.
Comment #38
dawehnerI'm not sure why we have to take back the rename ... in case we use something like this ... which I actually wanted to include :)
Comment #39
wim leersNow that makes sense :)
Comment #40
dawehnerCool :)
Comment #41
br0kenWhat do you think about replacing
returnstatement here by$this->format = $this->formatsto avoid code duplication?Comment #42
br0kenJust as an another opinion. In this case user definitely will get triggered an error about deprecation, even if method called with
NULLas an argument.Comment #43
dawehnerSure why not.
Comment #44
wim leersI like this even better. Even clearer that this method is decorating the parent method, but only for BC, and it'll be removed in 9.0.0.
Thanks, BR0kEN!
Comment #46
br0kenJust bringing back RTBC.
Comment #47
catchCommitted/pushed to 8.4.x, thanks!
Comment #49
wim leersYay, improved maintainability!
Comment #51
quietone commentedpublish the change record