Closed (fixed)
Project:
Drupal core
Version:
8.3.x-dev
Component:
migration system
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
31 Mar 2016 at 20:49 UTC
Updated:
18 May 2017 at 14:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
edysmpComment #3
heddnWhat are the efficiencies gained by moving the logic? Is it performance? Plus needs tests.
Comment #4
mikeryanFor context, I see that the use case is #2698067: Make idlist command support multiple sourceids. Not a matter of efficiency, but generality - it's better to guarantee the proper ordering of multi-value source keys back at the source, than only when hashing them.
Comment #6
mitrpaka commentedTesting if needs re-roll and had some offset. Updating patch.
Comment #7
edysmpComment #8
mikeryanSo far so good, now for testing.
Comment #9
mitrpaka commentedInitial test case added.
Comment #10
mikeryanJust a little documentation needed, I think.
Let's specify that the result is ordered according to the order in $this->sourceIds.
Four array functions in one line makes this a bit... dense - it takes running through what's happening here from the inner calls outwards to understand how it works. A comment would be helpful, explaining that array_flip(array_keys()) presents a keyed array in the properly order, and merging with array_intersect_key fills in the values.
Comment #11
mitrpaka commentedInitial documentation added. As I'm not native English speaking person, please help on proper wording. Thanks.
Comment #12
mikeryanI think that's fine, thanks!
Comment #13
alexpottHmmm ugh the docs for this say
We should have used reflection for that. Because this change could break existing migrate plugins. I guess we should try and work out how worth it this change actually is.
Comment #14
mikeryanComment #15
mikeryanHrrm, yes, "public only for testing purposes" is
an abominationnot our best work - but, fixing that would be a matter for a separate issue.So, I was going to say I don't see how this would break any existing migrate plugins. It's Row::getSourceIdValues() whose behavior is being expressly changed, and that change is from an unspecified ordering of the returned array to one that is ordered by the source ID definition, which shouldn't break anything unless it were depending on whatever order it happened to be getting (and note that A. Most often there's only one field, and B. Most of the time even with multiple fields they'll usually be in the right order anyway).
However, turning it over in my mind, there is actually a subtle BC break here - the $source_id_values argument to getSourceIDsHash() previously could be in any order because it sorted them, but now it will require the incoming array to already be sorted. As it happens (as near as I can see), all the core usages either pass through Row::getSourceIdValues() or are inherently sorted, but we can't guarantee that will always be the case. At this point, I'm questioning as @alexpott did whether this is worthwhile - it seems safer to just leave well enough alone and guarantee the source fields are sorted (if somehow the order of fields for a given row differed between runs, that would lead to some *very* difficult to diagnose problems, I think). If we are to go forward, at the very least getSourceIDsHash() needs to document that the input array needs to be properly sorted.
@edysmp/@mitrpaka - What do you think? Do you still want to pursue this?
Comment #16
mikeryanOh, but back to the original use case - we could still make Row::getSourceIdValues() sort its return value properly, but leave the sorting in getSourceIDsHash() alone.
Comment #18
mikeryanPer my last comment, this could still be done if we remove the change to getSourceIDsHash().
Launching tests to confirm, but this likely will need a reroll at this point...
Comment #19
jofitzRemoved the change to getSourceIDsHash() and updated array syntax.
Comment #20
mikeryanLooks good, thanks!
Comment #21
alexpottThis comment should just describe we want to occur rather than be a verbal description of the implementation. Ie. something like
Return the source values in the same order as the source identifiers.Mind you we could consider omitting this given the @return just above.Why not just
array_merge($this->sourceIds, array_intersect_key($this->source, $this->sourceIds));since the keys are already properly ordered and array_merge() will replace the values using the array_interest_key() return?Comment #22
jofitzComment #23
mikeryanChanges look good to me.
Comment #25
jofitzRe-tested - all fine, back to RTBC.
Comment #26
alexpottDoes this mean we can remove...
And just do:
The code that checks
if (!isset($source_id_values[0])) {looks super brittle.Comment #27
heddnRe #26: Yes, we should be able to get rid of that. Do we have tests? I'm sure we do, otherwise things would start falling on their face.
Comment #28
jofitzLet's see what the testbot thinks of that change...
Comment #29
heddnAnd back to RTBC.
Comment #31
heddnRandom testbot failure.
Comment #33
jofitzCome on, testbot! Back to RTBC.
Comment #35
joelpittetComment #36
gábor hojtsyHm, so this is a public function but the change affects what it expects as its argument, so at least it would come with a docs change? What about others possibly invoking this method?
Comment #37
heddnComment #38
tomogden commented#36: Doc change now specifies what is expected.
Comment #39
gábor hojtsyHm, as per #15, @mikeryan was leaning to keep the behavior as-is in my reading. It would be nice to get a confirmation form him or to keep the logic in line with his comment.
(emphasis mine)
Comment #40
mikeryanRight, in #26 @alexpott asked if we could remove the sorting code from getSourceIDsHash(), and in response it was removed. However, as I pointed out in #15, although existing calls to getSourceIDsHash() will pass the source in sorted, if anyone in contrib/custom modules is calling it without sorting the keys, they'll get a very subtle break in that the hashes won't necessarily match up. I think we should leave getSourceIDsHash() as-is - it needs to continue guaranteeing that the IDs are sorted before hashing.
Comment #41
catch#37 has the documentation change but is missing the rest of the patch. Does it just need to be combined with #28?
This issue took a couple of turns so tagging for issue summary update.
Comment #42
mohit_aghera commentedMerging patch of #28 and #37
Comment #43
mohit_aghera commentedComment #44
mohit_aghera commentedRemoving this change mentioned by Mike.
Comment #45
mikeryanComment #46
gábor hojtsyThanks for moving this forward. Just some small updates left AFAIS.
This added part of the comment is not true anymore, so it should be removed. IMHO a newline before @internal should also be added.
Comment #47
gaurav.kapoor commentedComment #48
mikeryanComment #50
gábor hojtsyThanks for the update. Also this now only does what the issue summary said, so no need to update the issue summary. The change is backwards compatible given that no ordering was ensured on getSourceIdValues() before. Committed!