Closed (fixed)
Project:
Book
Version:
3.0.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
15 Dec 2025 at 16:23 UTC
Updated:
7 Feb 2026 at 22:49 UTC
Jump to comment: Most recent
Upgrading from a fresh book 2.0.x installation.
Getting this error:
TypeError: Cannot access offset of type string on string in book_post_update_allowed_child_type_default6
Stack of errors:
[error] TypeError: Cannot access offset of type string on string in book_post_update_allowed_child_type_default6() (line 148 of /www/web/modules/contrib/book/book.post_update.php) #0 /www/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(291): book_post_update_allowed_child_type_default6(Array)
> #1 /www/vendor/drush/drush/includes/batch.inc(257): Drush\Commands\core\UpdateDBCommands::updateDoOnePostUpdate('book_post_updat...', Array)
> #2 /www/vendor/drush/drush/includes/batch.inc(204): _drush_batch_worker()
> #3 /www/vendor/drush/drush/includes/batch.inc(75): _drush_batch_command('1')
> #4 /www/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(145): drush_batch_command('1')
> #5 [internal function]: Drush\Commands\core\UpdateDBCommands->process('1', Array)
> #18 {main}.
> TypeError: Cannot access offset of type string on string in /www/web/modules/contrib/book/book.post_update.php on line 148 #0 /www/vendor/drush/drush/src/Commands/core/UpdateDBCommands.php(291): book_post_update_allowed_child_type_default6(Array)
> #1 /www/vendor/drush/drush/includes/batch.inc(257): Drush\Commands\core\UpdateDBCommands::updateDoOnePostUpdate('book_post_updat...', Array)
> [warning] Drush command terminated abnormally.
In ProcessBase.php line 171:
Unable to decode output into JSON: Syntax error
TypeError: Cannot access offset of type string on string in book_post_update_allowed_child_type_default6() (line 148 of /www/html/modules/contrib/book/book.post_update.php).
Install book 2.0.x with this configuration:
book.settings.yml
allowed_type_book: 1
block:
navigation:
mode: 'all pages'
child_type_book: book
Then upgrade to book 3.0.x
Then observe bug.
See code in merge request
Review code in merge request
Allows upgrades without crashing
See merge request
See merge request
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
joseph.olstadwatch pipelines
Comment #4
smustgrave commentedWill take a look before 3.0.0 but this seems like it’s changing too much. Will take a different approach
Comment #5
smustgrave commentedWere you using a patch by chance?
I did a fresh install of 2.0.x
Configured the book settings to use Article and Basic page with Basic page as the child type
Switched to 3.0.x
Update hooks ran just fine
Config exported correctly.
Comment #6
joseph.olstad@smustgrave
it's been a month now however have a look at the steps to reproduce again that I documented.
Comment #7
smustgrave commentedSeems like it may have been a unique issue not sure how you ended up with allowed_type_book: 1
Comment #10
philipnorton42 commentedI can see the same thing happening on my site.
The error is happening because the `allowed_child_type_default6` hook happens before `convert_allowed_types_to_structured`, and the error is caused because `convert_allowed_types_to_structured` is changing the structure of the config that the `allowed_child_type_default6` hook is then updating.
The order makes sense because the post update hooks are executed alphabetically (see the api docs).
This section here:
"In contrast to hook_update_N() the alphanumeric naming of functions in the file is the only thing which ensures the execution order of those functions. If update order is mandatory, you should add numerical prefix to NAME or make it completely numerical."
It looks like someone has tried to set one of the hooks to fire last by adding the 6 to the end, but as the docs says the order should be determined by the prefix.
Since there is an order to the hooks in this file can I suggest changing the post update hook names to the following:
- book_post_update_convert_allowed_types_to_structured -> book_post_update_1convert_allowed_types_to_structured
- book_post_update_allowed_child_type_default6 -> book_post_update_6allowed_child_type_default
I'll create a PR with the change in now.
Comment #12
mdranove commentedI was able to repro the error, not sure how I got there but my book.settings looked like
the post update hook tries to update assuming there is an associative array for allowed_types
However, as noted above, this is not always the case. Not sure why.
I am confused though about how @joseph.olstad ended up with those configs. I ran
git grep -F "allowed_type_book" $(git rev-list --all)on 1.x 2.x and 3.x and couldn't find it anywhere so I don't think this will really work in that case.I opened a new MR with my fix, but then I noticed a comment just now from @philipnorton42. That fix looks even better, I just tried it and it worked for me.
Comment #14
philipnorton42 commentedThanks for the comment mdranove, appreciate you testing that so quickly :)
I've reverted the code on the branch that joseph created since I think it's detracting from the actual issue, where the hooks are just triggering out of order. I've updated the MR with the change to the hook names, which works when I've run some tests on it.
Comment #15
philipnorton42 commentedComment #16
mdranove commentedComment #18
smustgrave commentedThanks all!
Comment #20
joseph.olstadI inherited allowed_type_book from sylus year 2021
I'm not sure what uses this, no reference in the code base other than this entry in book.settings.yml. I'd have to dig a bit more. I only see one D9 book patch from the 2021 build and it doesn't have any reference to this.
Comment #21
joseph.olstadI've pulled/ lightly massaged the book 3.0.x changes into livre 1.0.7