#2226533: Changes to the Language class due to the LanguageInterface (followup) is proving troublesome to get to RTBC
It has many small issues that when combined are proving difficult to get right, so the next step is to
harvest small parts of the patch in turn.
This issue is about extracting the parts that convert the weight property of language in a protected property.
This issue starts by extracting code from comment #244
This single strand from the other issue although small, will still touch many parts of the system hence "Will cause conflicts"
Comment | File | Size | Author |
---|---|---|---|
#45 | 2304403.45.patch | 5.25 KB | YesCT |
#44 | interdiff-42-44.txt | 682 bytes | martin107 |
#44 | 2304403-protect_language_weight-44.patch | 5.07 KB | martin107 |
#42 | interdiff-40-42.txt | 1.19 KB | martin107 |
#42 | 2304403-protect_language_weight-42.patch | 5.02 KB | martin107 |
Comments
Comment #1
martin107 CreditAttribution: martin107 commentedFirst attempt, the possibility that I have missed something is high, but the fix should be obvious.
Please note the isset line in the getWeight() function.
Comment #3
martin107 CreditAttribution: martin107 commentedAhem the problem is simple .. if only I had seen it first time..
Comment #5
YesCT CreditAttribution: YesCT commentednoting #2151223: Add a method to SortArray to sort by weight and title
Comment #6
martin107 CreditAttribution: martin107 commentedPostponing on resolution of #2304651: Core Language sort() should not work, needs to use name instead of default title
Comment #7
martin107 CreditAttribution: martin107 commentedI am opening up this issue again.... it look like [ #2304651] may have solved the random fail issue.
In the long term the plan is :-
Apply its fix to all issues, and the EntityQueryTests should go green that will provide some confidence, BUT the next step,
is to run version of the patch 50 times over in #2254011: Drupal\system\Tests\Entity\EntityQueryTest random failure
I am just folding in the change here ... this issue has other problems to fix first.
Comment #9
martin107 CreditAttribution: martin107 commentedRestored sort line to its original :-
Language::sort($this->languages);
Comment #11
martin107 CreditAttribution: martin107 commentedDrupal\language\Tests\LanguageConfigurationTest now passes locally.
Comment #12
tstoecklerWhy is this needed?
Since the property defaults to
0
it seems it shouldn't be.Comment #13
martin107 CreditAttribution: martin107 commented@tstoeckler
I agree in part ....
Can I rephrase the question
The default values are made available for another programmer, but its use is not tightly enforced. There is no type checking. and nothing to stop the construction of a language with a weight not set ( ie set to null ). This will cause difficult to see issue in the long run.
What goes for weight, can also be said of locked ( https://www.drupal.org/node/2226533#comment-8942261 )
I have made the case in the past, in another issue, for these values to made-safe at point to intake. ( in setters or constructors )
But I was going for the simplest solution here, well easiest to review ... we have a maintenance problem at the moment as
this "ternary operator" checking is made at two places in core and it seemed natural to consolidate the fixup in the getter.
Anyway I would like to hear what you think?
Comment #14
tstoecklerSure I'm not opposed to doing it that way. I also like type-checking for primitive types in constructors but that's not something we generally do in core. So I think it would be more consistent to just drop the ternary. But again, it's your patch, so feel free to keep it :-). If this comes back green it's RTBC, so marking as such, as the testbot will set me straight otherwise.
Comment #16
martin107 CreditAttribution: martin107 commentedTo cut away at my own argument
$language_entity->weight = isset($language->weight) ? $language->weight : 0;
occurs at only ONE place language_save :-
Other properties may be typed check in multiple places ( I am looking at you locked ) but not weight.
So I am returning getWeight() to the more consistent form..
[ I cannot use isset(func()) so I am using null !== func() instead. Its is PHP thing.]
It is a truism that many of my concerns about loose type checking in core could be resolved by providing better documentation above the constructor...
BUT even I think this would be overkill in this case ... using Language::defaultValues is a specialist thing that not many developers down the line
are going to want to do and for those that do there are plenty of examples in core for people to copy..
-----------------------------
I have fixed a minor nit pick in EntityTranslationTest but it is not the complete story, errors persist.
Comment #18
martin107 CreditAttribution: martin107 commentedI will look at this again soon, but maybe not until the weekend
Comment #21
martin107 CreditAttribution: martin107 commentedI am postponing because I am hopeful, that #2226533: Changes to the Language class due to the LanguageInterface (followup) is on its way to being committed.
Comment #22
martin107 CreditAttribution: martin107 commentedRe-opened in light of https://www.drupal.org/node/2226533#comment-9023095
Comment #23
martin107 CreditAttribution: martin107 commentedPatch no longer applied. Reroll.
Comment #25
martin107 CreditAttribution: martin107 commentedEntityTranslationTest can be made to pass by changing the definition of Drupal\Core\Language\Language::weight from
protected to public,
So it looks like not all code of the form language->weight has been changed to language->getWeight()
I have looked but cannot find it. :(
Comment #26
martin107 CreditAttribution: martin107 commentedNeeded reroll.
Comment #28
martin107 CreditAttribution: martin107 commentedThe original intent behind this issue is still valid.
#2226533: Changes to the Language class due to the LanguageInterface (followup) is too large and too cumbersome to get reviewed... so splitting off small segments that are obviously right, and can be reviewed faster.
Rerolling is complete .. NowI have finally fixed the failing tests by copying over changes from the parent issue.
Comment #29
martin107 CreditAttribution: martin107 commentedComment #31
martin107 CreditAttribution: martin107 commentedReroll triggered by
#2332739: Remove SortArray::sortByWeightAndTitle
as is to be expected a file diff between #28 and #31 shows only a simplification of Drupal\Core\Language\Language::sort()
PS I am removing the will case commit conflicts tags .. it was inherited from its parent which typically needs a daily reroll.. This issue is much smaller and has gone for weeks without a reroll...
Comment #32
YesCT CreditAttribution: YesCT commentedweight has to have a value now, so we dont need the ternary.
We can do something like the other issue was.
(I guess it is possible that another class would implement LanugageInterface and not have an initial value on its weight property, or do some other crazy implementation. But I think we can expect other implementations to be such that getWeight will return a value. Cause we dont do this in other places where we use the value returned by getWeight.
Comment #33
YesCT CreditAttribution: YesCT commentedComment #34
martin107 CreditAttribution: martin107 commentedPatch no longer applies.
@YestCT I will remove that ternary ... later ( tonight )
Just to cross reference, this other active issue, which I think I agree with.. aims to remove the setWeight()
So in the future the patch here may become even smaller.
Comment #35
martin107 CreditAttribution: martin107 commentedJust a straight reroll, for now.
one conflict which was trivial to resolve.
Comment #36
martin107 CreditAttribution: martin107 commentedSnip snip ..now using $language->getWeight() without protection.
Comment #37
martin107 CreditAttribution: martin107 commentedNeeds a reroll... there is a sprint so I am just signalling that I am working on this now.
Comment #38
martin107 CreditAttribution: martin107 commentedComment #39
martin107 CreditAttribution: martin107 commentedpatch is simpler because common.inc langauge_save() has gone (Yay!)
Comment #40
Désiré CreditAttribution: Désiré commentedRerolled patch from #39.
Comment #41
YesCT CreditAttribution: YesCT commentedI think we should protect the ConfigurableLanguage weight property also. (alexpott asked for the simultaneous change in Language and ConfigurableLanguage on another similar issue).
Comment #42
martin107 CreditAttribution: martin107 commentedHurumph
I could only see one place to alter, other than the definition itself.
I guess testbot will give me a better answer.
Comment #44
martin107 CreditAttribution: martin107 commentedLanguageConfigurationTest now passes.
Comment #45
YesCT CreditAttribution: YesCT commenteda reroll (for #2340571: LanguageInterface needs isLocked method for the locked property.)
let's see how it looks when the testbot runs, and then we can look in detail.
Comment #46
YesCT CreditAttribution: YesCT commentedComment #47
dawehnerAwesome!
Follow up suggestion: #2350941: Simplify $language max weight code using max()
Comment #48
alexpottCommitted c52c5f9 and pushed to 8.0.x. Thanks!
Comment #50
YesCT CreditAttribution: YesCT commentedthanks! we are making progress!
now on to
#2341341: Change public 'name' property access on languages to getName() and add back setName()
and
#2340667: Protect Drupal\Core\Language\Language::id, and use getId()