Support from Acquia helps fund testing for Drupal Acquia logo

Comments

grahl’s picture

Since exclude can be unset I changed the code to check for its existence. I have not checked how exclude is produced, so I am not certain whether the presence of exclude could also evaluate to true/false/unset instead of set/unset.

grahl’s picture

Project: Migrate Upgrade » Drupal core
Version: 8.x-1.x-dev » 8.0.x-dev
Component: Code » migration system

Moved to core since the issue occurs in migrate_drupal.

benjy’s picture

FileSize
14.14 KB
+++ b/drupal/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ViewMode.php
@@ -26,7 +26,7 @@ protected function runQuery() {
+        if (isset($field_row['display_settings'][$view_mode]) && !isset($field_row['display_settings'][$view_mode]['exclude'])) {

This changes the logic, previously we were testing whether exclude was true/false where as now we're testing if the field is set. if exclude was true, this code would be wrong.

Re-uploading the patch to trigger the bot, I wonder if our tests have this covered.

Status: Needs review » Needs work

The last submitted patch, 3: 2237831-28.patch, failed testing.

benjy’s picture

Status: Needs work » Needs review
FileSize
1018 bytes

Wow, I uploaded the wrong patch last time :/ Try again...

Status: Needs review » Needs work

The last submitted patch, 5: check_for_exclude_index-2348447-1.patch, failed testing.

Cristian.Andrei’s picture

fixed patch

Cristian.Andrei’s picture

Status: Needs work » Needs review

The last submitted patch, 1: check_for_exclude_index-2348447-1.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: undefined_index_exclude-2348447-7.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
994 bytes

I'm getting inconsistent test results, but here goes.

benjy’s picture

I think the first part was only meant to check if the $view_mode was set. I'm not entirely sure if 'exclude' is always set or whether it's true or false we could check that and then write the code based on that assumption otherwise we could handle all instances:

 if (isset($field_row['display_settings'][$view_mode]]) && (!isset($field_row['display_settings'][$view_mode]['exclude']) || !$field_row['display_settings'][$view_mode]['exclude']))
quietone’s picture

FileSize
1.03 KB

Right, see your point. I was revisiting what php does when testing an unset variable in arrays and well, got so busy looking at the trees I missed the forest, as it were.

I too don't know if exclude is always set, but is when it is, it is 0 or 1.

The changed line is 81 characters. According to Line length and wrapping that seems to be allowed in this case. Let me know if it should be changed.

Status: Needs review » Needs work

The last submitted patch, 13: 2348447-13.patch, failed testing.

Status: Needs work » Needs review

quietone queued 13: 2348447-13.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 13: 2348447-13.patch, failed testing.

quietone’s picture

FileSize
1.03 KB

Oh dear. Maybe this will be third time lucky.

benjy’s picture

Status: Needs work » Needs review
benjy’s picture

Well this now covers both the possibility it's true/unset and true/false. I'm OK with that.

Can we update a test to cover the new "unset" case?

quietone’s picture

It seems like a good idea to add a test. But I'm not currently able to do that.

I've got the time if anyone is willing to help me learn it.

benjy’s picture

To test this, look at the "Dump" file that provides the table "content_node_field_instance". From there, remove the exclude setting entirely from the display settings on of the view modes. Then we should be able to assert that the view mode is still imported. It's likely that we already have tests that assert this.

benjy’s picture

Status: Needs review » Needs work
quietone’s picture

Status: Needs work » Needs review
FileSize
3.64 KB
3.71 KB

@benjy, thx. And here's a patch.

Can you tell me why only the view_mode 'preview' is tested in ViewModeTest.php and not the other ones?

benjy’s picture

No I can't think of any good reason why we're only testing view_mode 'preview' and no others in the unit test. Likely the view modes were added for testing something else and then the unit test never got updated. That's out of scope for this issue.

Patch looks good. Could you please post a copy of the patch without the new fix so we can confirm that the test fails?

quietone’s picture

FileSize
583 bytes

@benjy Is this what you mean?

The attached patch will cause 2 failures, one in ViewMode.php about the undefined index and another from MigrateFieldFormatterSettingsTest.php. Then, apply 2348447-23.patch and the tests pass.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

Yes that is what i mean. Thank you.

Issues is RTBC as long as #25 fails which it should.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 2348447-25-fail.patch, failed testing.

benjy’s picture

Status: Needs work » Reviewed & tested by the community

#23 is RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
+++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php
@@ -31,7 +31,7 @@ protected function runQuery() {
+        if (isset($field_row['display_settings'][$view_mode]) && isset($field_row['display_settings'][$view_mode]['exclude']) && !$field_row['display_settings'][$view_mode]['exclude']) {

+++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/d6/ViewMode.php
@@ -26,7 +26,7 @@ protected function runQuery() {
-        if (isset($field_row['display_settings'][$view_mode]) && !$field_row['display_settings'][$view_mode]['exclude']) {
+        if (isset($field_row['display_settings'][$view_mode]) && isset($field_row['display_settings'][$view_mode]['exclude']) && !$field_row['display_settings'][$view_mode]['exclude']) {

Don't we want to create a view mode if exclude is not set?

So this could be just empty($field_row['display_settings'][$view_mode]['exclude']), no?

benjy’s picture

@alexpott, thanks for the review. I believe you're right.

@quietone, lets add a test that verifies the new view mode you added to the dump is migrated. Right now, that should fail (post a patch to prove it).

Then, lets update this logic as suggested by alexpott and hopefully the new and existing tests should pass.

quietone’s picture

Status: Needs work » Needs review
FileSize
3.84 KB

OK. Here are the tests, which should fail.

Status: Needs review » Needs work

The last submitted patch, 31: 2348447-31-newtests.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
5.76 KB

And a patch

Status: Needs review » Needs work

The last submitted patch, 33: 2348447-33.patch, failed testing.

quietone’s picture

OK. Nice to have the errors confirmed, I've been getting inconsistent results.

benjy’s picture

Them errors are related to the tables for the new fields you added been missing in the dumps. You should be able to copy another field to create those tables.

quietone’s picture

Status: Needs work » Needs review
FileSize
6.85 KB

@benjy, thx.

Once again with the new tests that will fail.

quietone’s picture

FileSize
3.13 KB

And a new patch

quietone’s picture

FileSize
8.78 KB

Forgot to upload the patch.

The last submitted patch, 37: 2348447-37-newtests.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 39: 2348447-38.patch, failed testing.

quietone’s picture

Hmm, that test passes when I run it by itself.

quietone’s picture

Status: Needs work » Needs review
FileSize
6.88 KB

New tests that will fail.

The change is to add "exclude => 1" for the print view mode in field_test_exclude. That will allow the existing tests to pass and still allow the testing of migrating a field where exclude is not defined.

quietone’s picture

And the patch.

The last submitted patch, 43: 2348447-43-newtests.patch, failed testing.

quietone queued 44: 2348447-44.patch for re-testing.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

Great job @quietone. I checked the existing tests and we already had coverage for testing the lack of display modes that are excluded in the dumps.

The only confusing thing here is that we have a field called field_test_exclude which is actually to test exclude being unset but I think we can let that through, hopefully the dumps will be auto generated soon once #2348875: Improving our dump files lands.

quietone’s picture

Thanks @benjy. I'm glad we agree about the existing tests.

And I wasn't too happy with the name either. And now that I read your comment, I've changed field_test_exclude to field_test_exclude_unset and attached a new patch. I don't mean to make more work for anyone, but the name change does make it clearer what is being tested. So, for me, it is worth changing the name.

benjy’s picture

Great, still RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 48: 2348447-48.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
8.94 KB
1.47 KB

Reroll

benjy’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs tests

This issue is a unfrozen change (migrate) as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed 4e06a75 and pushed to 8.0.x. Thanks!

  • alexpott committed 4e06a75 on 8.0.x
    Issue #2348447 by quietone, benjy, grahl, Cristian.Andrei: Undefined...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.