Problem/Motivation
Quoting @effulgentsia from #2721595-69: Simplify REST configuration:
Sorry. A few more nits.
+++ b/core/modules/rest/src/Entity/ConfigDependencies.php @@ -102,6 +96,10 @@ protected function calculateDependenciesForMethodGranularity(RestResourceConfigI + if (isset($dependencies['module'])) { + sort($dependencies['module']); + }Either we assume that the result of this function always passes through DependencyTrait::addDependency() (which it does within
RestResourceConfig::calculateDependencies()) prior to being saved to storage or otherwise needing to be sorted, or we do not assume this. If we assume it, then we shouldn't need this hunk, but we should add docs to the function to clarify this assumption. If it's only to make a unit test pass, then perhaps the unit test should be the one to sort. If we do not assume this, and therefore, require this function to sort, then it should mimic DependencyTrait::addDependency() and also ensure uniqueness.+++ b/core/modules/rest/src/Entity/ConfigDependencies.php @@ -183,7 +182,71 @@ protected function onDependencyRemovalForMethodGranularity(RestResourceConfigInt + if (in_array($format, $rest_config->getFormats('GET'))) { + $configuration['formats'] = array_diff($configuration['formats'], $removed_formats); + }Per #64.2, we shouldn't assume GET is defined. Technically, this code doesn't, as the implementation of getFormats() ignores the passed-in method, but that's not obvious from reading this code in isolation. Any reason not to simply use
$configuration['formats']instead of$rest_config->getFormats('GET')?+++ b/core/modules/rest/src/Entity/ConfigDependencies.php @@ -183,7 +182,71 @@ protected function onDependencyRemovalForMethodGranularity(RestResourceConfigInt + if (in_array($auth, $rest_config->getAuthenticationProviders('GET'))) { + $configuration['authentication'] = array_diff($configuration['authentication'], $removed_auth); + }Same as above, but for getAuthenticationProviders().
And then him again in #2721595-71: Simplify REST configuration:
As I looked more at #69, I couldn't find a reason for those points to block commit, so pushed to 8.2.x. A follow-up for #69 would be appreciated though.
This is that follow-up.
Proposed resolution
Fix the nits.
Remaining tasks
Fix the nits.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | 2773185-26.patch | 6.09 KB | wim leers |
Comments
Comment #2
dawehnerAdding a tag.
Comment #3
wim leers#2: Sorry, I started addressing this already. While minor and simple stuff, you kind of need to know how all these things work to address it the appropriate way.
Comment #4
dawehnerWell, IMHO we should mimic the behaviour and ensure uniqueness actually. As someone, who builds sites, having deterministic sorting on CMI is a huge deal. It helps you a lot with actual adapting configuration quickly.
Comment #5
wim leersBut we already have that.
\Drupal\rest\Entity\ConfigDependencies::calculateDependencies()was just duplicating it. So sorting was happening twice.Because:
\Drupal\rest\Entity\RestResourceConfig::calculateDependencies()does:(Note the
addDependency()call!!!!!)\Drupal\Core\Config\Entity\ConfigEntityBase::addDependency()does:And note: that
addDependencyTrait()is an aliased trait method:\Drupal\Core\Entity\DependencyTrait::addDependency()finally does:In other words: @effulgentsia merely pointed out that we're doing duplicate (yet incomplete, because not guaranteeing uniqueness) work. And I agree with him. That's why I added the documentation to show why
\Drupal\rest\Entity\ConfigDependencies::calculateDependencies()does not need to care about either uniqueness or sorting, because that it handled later. It only provides the starting point data.Comment #6
wim leersComment #7
dawehnerSo can we adapt the testcases instead to be presorted? Its confusing to have a sort there. Its almost like adapting the test for the sake of making it pass ...
Comment #8
wim leersI don't think it's like that at all. What we're doing, is a set comparison. So, just made that more clear.
(Copied that over from
\Drupal\big_pipe\Tests\BigPipeTest::assertSetsEqual().)Comment #9
dawehnerSo wait, isn't the order basic_auth, hal, serialization what we expect to see, so in case we don't see that, there is some bug somewhere?
Comment #10
wim leersWhy would they be ordered alphabetically?
Comment #11
dawehnerWell, you want some sort of stable ordering, unless you want to kill yourself when dealing with config merges.
Comment #12
wim leersYes, and that's what I explained in #5 in detail, and what @effulgentsia wrote originally: what
ConfigDependencies::calculateDependencies()returns is passed into\Drupal\Core\Entity\DependencyTrait::addDependency(), which handles sorting for us.So this is testing the return value of
ConfigDependencies::calculateDependencies(), which does not need to be sorted. Because sorting happens at a later stage.Comment #13
effulgentsia commented@dawehner: does the docs rewording in this patch help clarify or do you still have concerns?
Also, I changed a newly committed function from #2721595-70: Simplify REST configuration from public to protected in this patch. It should have been to begin with, and was an oversight to have made its way in as public.
I kind of wonder if we should also mark the entire
ConfigDependenciesclass as @internal. Or is there a use-case from someone to use it from outside ofRestResourceConfig? If we want to do that, let's do it in a separate issue though.Comment #14
effulgentsia commentedHelps to upload the patch :)
Comment #15
effulgentsia commentedShouldn't this be
array_diff()rather thanarray_diff_assoc()? Which means, is this function working at all? It doesn't appear to actually assert anything; it only returns a boolean.Comment #16
dawehnerWell, docs don't really help. You have an existing config file, adapt something, like adding hal_json as support, and someone else adds oauth support. Suddenly, due to, as it seems, non deterministic ordering, you maybe get a conflict, even there wasn't really a need for it. This is purely an argument driven by working on real sites. CMI has done a lot of work to ensure that stuff like the field display configuration changes as minimal as possible, so I'm just trying to ensure we have the same here. In order to achieve that, some form of deterministic order would be helpful.
Comment #17
effulgentsia commentedRight. We do have a deterministic order, so long as the only caller of
ConfigDependencies::calculateDependencies()isRestResourceConfig::calculateDependencies(), which is the case in core. Hence my question in #13 of whether we should markConfigDependenciesas @internal. Does that class have any purpose other than being a helper class toRestResourceConfig?Comment #18
dawehnerThank you @effulgentsia for your explanation.
I totally agree with you that this should be an
@internalclass. IMHO we should do that more often :)Given that its deterministic, we should, at least IMHO, reflect that in the test case but using exactly the deterministic order of dependencies we expect it to be.
Comment #19
wim leersYes, +1!
Yes! Did that in this reroll.
It's deterministic, but you still get a different dependency order depending on whether "method" vs "resource" granularity is used. But, if we play with the test cases so that the first method already uses
basic_auth, then we can make sure they end up returning the exact same ordered list of dependencies!Comment #20
dawehnerSo the order is in the order of dependencies in the file? That sounds reasonable
Comment #21
wim leersYep :)
Comment #22
alexpottWhilst doing this let's make the comparison strict for sanity.
Are we fixing a bug?
Comment #23
effulgentsia commentedDiscussed with the other committers, and we're ok with this going in any time during 8.2.x, even during RC.
Comment #24
xjmFor #22.
Comment #26
wim leers#22:
sort()(see third hunk in patch). This is what @dawehner asked in #7 and later comments.Only change in this reroll:
in_array(X, array)->in_array(X, array, TRUE— i.e. strict checking. Since that's absolutely trivial, re-RTBC'ing.Per #23, moving back to 8.2.x.
Comment #28
wim leersApparently the automated re-testing hit a DrupalCI abortion, and hence this was marked NW. The patch did not actually fail. Re-testing.
Comment #29
alexpottCommitted and pushed 713d4e9 to 8.3.x and 90b725c to 8.2.x. Thanks!