I'm working on a migration from Drupal 7. The migration for redirects seemed to work fine. The status_code for all rows is NULL, but the schema seems to allow for that, so I don't see any problem there. However, when I try to access one of those redirects I get the following exception:
InvalidArgumentException: The HTTP status code "0" is not valid.
in Symfony\Component\HttpFoundation\Response->setStatusCode() (line 464 Symfony\Component\HttpFoundation\RedirectResponse)
This is being called from line 168 Drupal\redirect\EventSubscriber\RedirectRequestSubscriber
Is there something I'm missing? Should the module handle cases when the status_code is NULL or 0? Or is that a bug in the migration or my Drupal 7 database?
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff-3082364-7-13.txt | 1.57 KB | huzooka |
| #14 | redirect-fix_status_code_property_migration-3082364-13.patch | 12.36 KB | huzooka |
| #7 | interdiff-3082364-4-7.txt | 11.65 KB | marvil07 |
| #7 | 3082364-7.patch | 12.01 KB | marvil07 |
| #7 | 3082364-7-tests-only.patch | 11.27 KB | marvil07 |
Comments
Comment #2
maddentim commentedCurious if you found a solution here. I had the same condition. I ended up going into the database directly and running a bit of sql to add the status code. Seemed to work.
Comment #3
nicolasambroise commentedHey, I have the same error in my log and my Website was also created with the D7 migration module.
@maddentim can you share with us your SQL script ?
Comment #4
rd.michael commentedI ended up patching the migration source
src/Plugin/migrate/source/d7/PathRedirect.phpto this to handle scenarios where the D7redirect_default_status_codewas not defined. I found this can happen if you never save the redirect settings page in D7 and just use the defaults. So perhaps the easier solution for most of you is to simply go into your D7 website and save the redirect settings page in the admin and re-migrate. However, for us, we are migrating many sites across a multi-site setup and re-migrating all the time so this made more sense.Comment #5
sashken2 commentedI have same problem too, after update from D7 to D8
Comment #6
andy_read commentedI've also come across this issue and it seems the root problem is that D8 redirects do not behave in the same ways as D7. In D7 if the individual redirect is not set then it uses the system-wide default. But in D8 this default is only used when new redirects are created. So one approach would be to fix this behaviour.
Or it may be possible to enhance the migration to use the default if the response code is not set for a redirect.
Or if you want the quick fix in SQL, then first check what the current status is with:
SELECT count(*), status_code FROM redirect group by status_code;In my case a few were already set to 301, but most were NULL. So I was OK to just set everything with:
update redirect set status_code=301;Boom! (drush cr) Done!
To be a little more selective, safer and performant then:
update redirect set status_code=301 where status_code is NULL;Comment #7
marvil07 commentedI got into this problem too in the context of a d7 to d8 migration.
@rd.michael evaluation of the reason is the same I found for my case: d7
redirect_default_status_codecan be unset.I am attaching several patches here.
The minimal patch for the fix would be the following.
I have not tried the tests locally yet, so let us see what testbot says.
Also, I am not sure if we want to reuse code from fixtures, and if so, how; feedback is welcomed.
Comment #10
benjifisherI am working with @marvil07 on a migration project, and I tested his patch from #7 on that project. It works as expected.
Thanks for adding a test, and for including a test-only patch! I did not review the test very thoroughly, but I did check that the test-only patch fails in the expected way and that it is, in fact, a test-only version of the main patch. (The interdiff utility gets confused, but a direct diff of the two patches is easy.)
Outside the test, the change is simple and, as @marvil07 said, minimal. I am changing the issue status to RTBC.
After the patch, I see the following code in the source plugin:
I would rather use a class property, set in the constructor, than a static variable in a class method. I would also simplify the last two lines before the return to
(untested). Both of these points are out of scope for fixing the bug, but I will be happy to review an updated patch if anyone wants to make the changes.
Comment #11
m@ster commentedCan't apply patch to stable 8.x-1.6 D8.8.
Comment #12
benjifisher@M@ster:
The latest tag (8.x-1.6) is the same as the HEAD of the 8.x-1.x development branch. The patch in #7 applies cleanly when I try it.
How are you applying the patch?
Comment #13
huzookaComment #14
huzookaSimplified the default value assignment (DrupalSqlBase provides method for these kind of cases) and changed the value comparison to a clearer one.
Comment #15
huzookaComment #16
wim leersReview of #14
👍 This was indeed duplicating the logic of
\Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase::variableGet(), so this looks like a solid improvement to me!👍 This change makes sure we do not rely on an explicitly non-strict comparison, which is a crucial yet easy to miss detail. Therefore this code seems more futureproof.
Review of overall patch
🤓 This should use the FQCN.
🤓 The formatting here is really weird. But … pre-existing. So … 🤷♂️
✅ I was going to say: why not use a
@dataProvider? But that'd be too slow; migrations are very slow.Comment #17
christian le fournis commentedI was not able to apply patch #14 using composer using redirect 1.6
Comment #18
sseto commentedI applied patch #14 to 1.6, but didn't work. So I followed #6 and it worked.
Comment #19
wim leersThat's odd, because we're applying #16 on top of
drupal/redirectversion1.6just fine 🤔Comment #20
benjifisherFollow-up to #16.2:
Why not
instead? Or even
Or see my suggestion at the end of #10.
Comment #21
danchadwick commentedThis bug was found and a fix posted a year ago.
Critical bug (site is broken, PHP exception).
Fix is obvious (clear what's wrong).
Fix is trivial (simple one liner).
Tested by community.
Enough bike shedding and optimizing the leap year interrupt. I've wasted yet-another morning on an already-fixed-but-not-committed bug.
Comment #22
berdirCommitted, thanks.