Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
An exception message in Row.php should include the name of the property not just $id.
Original report:
The invalid exception for multi language, throw a non standard translation strings:
"$id is defined as a source ID but has no value." in core/modules/migrate/src/Row.php
if (!$this->hasSourceProperty($id)) {
throw new \InvalidArgumentException("$id is defined as a source ID but has no value.");
}
Proposed resolution
Add the name of the id to the exception message.
Translation is not added as per the coding standards, specifically item 3 in Basic conventions.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff_16-19.txt | 1.43 KB | ravi.shankar |
#19 | 3160323-19.patch | 1.4 KB | ravi.shankar |
#16 | interdiff_8-16.txt | 684 bytes | ravi.shankar |
#16 | 3160323-16.patch | 664 bytes | ravi.shankar |
#8 | 3160323-8.patch | 655 bytes | ravi.shankar |
Comments
Comment #2
John.nie CreditAttribution: John.nie commentedComment #3
John.nie CreditAttribution: John.nie commentedComment #4
John.nie CreditAttribution: John.nie commentedComment #6
quietone CreditAttribution: quietone as a volunteer commented@John.nie, thanks for the patch. Adding the name of $id will be helpful.
The @key needs single quotes,
"'$key' is defined as a source ID but has no value"
. Exceptions messages are not translated so the use of t() can be removed. See Php exceptions.Comment #7
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #8
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedThis patch might fix comment #6.
Comment #9
quietone CreditAttribution: quietone as a volunteer commented@ravi.shankar, thanks for the patch.
The unit test still needs to be fixed.
Comment #10
jungleIMO, should be just
throw new \InvalidArgumentException("'$id' is defined as a source ID but has no value.");
, no need to usespritf()
Comment #11
jungleIt's unclear what to do here, besides adding single quotes around
$id
, so adding a "Needs issue summary update" tagComment #12
quietone CreditAttribution: quietone as a volunteer commentedComment #13
quietone CreditAttribution: quietone as a volunteer commentedComment #14
jian he CreditAttribution: jian he commentedComment #15
quietone CreditAttribution: quietone as a volunteer commented@jian he, thanks for updating the title. I think you are asking for the exception message that is thrown in Row.php to be translated. However, Exception messages in Drupal are not translated. This is in the coding standards for exceptions, it is the 3rd item in Basic conventions. I don't know if there is an issue for adding translation for exception messages.
I'm changing the title based on my understanding. If I am wrong, please say so.
Needs work for fixing the two failing tests.
Comment #16
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedHere I have tried to fix failed tests of patch #8.
Comment #18
quietone CreditAttribution: quietone as a volunteer commentedThe format string for sprintf looks more like a format string for the t() function. Sprintf doesn't use an '@' symbol for conversion specifications. But there is no need for sprintf anyway. This just needs single quotes around the string $id so that it becomes
'$id'
.Then the exception message in testInvalidSourceIdKeys needs updating. And I think we should an a test of the exception message in testRowWithInvalidData() as well. That needs
$this->expectExceptionMessage("'nid' is defined as a source ID but has no value.");
@ravi.shankar, I am not aware of your experience or your knowledge with Drupal so please ignore if I am repeating things you already know. Before uploading a patch to let the testbot test it is better to test the patch locally in your own dev environment. That way you can test your ideas on just the one file you are working on and make multiple iterations easily. Setting up for testing is worth the time and effort. There is a handbook section that covers all aspects of PHPUnit in Drupal. Cheers.
Comment #19
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commented@quietone Thanks
Added a patch that might fix the failed tests.
Comment #20
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #21
jungleThe title is "Add property name to exception message in Row.php", but it's impossible to get the source property per
!$this->hasSourceProperty($id)
, so how to add the property name to the exception message?From my understanding, this issue is just adding single quotes, nothing more.
Comment #22
quietone CreditAttribution: quietone as a volunteer commented@jungle, yes it is about adding single quotes and I have finally updated the title.
The patch in #19 adds the missing single quotes around the name of the source id and the test is updated correctly.
Comment #24
alexpottCommitted 33a6866 and pushed to 9.1.x. Thanks!
As the ID is already included I think this is only a task.