Updating from 1.0.2 to 1.04 breaks the site

Created on 3 April 2023, over 1 year ago
Updated 29 March 2024, 8 months ago

Problem/Motivation

When updating from 1.0.2 to 1.0.4 Drupal will desist running upgrade. It'll only provide you with a rather unhelpful

Missing or invalid module
The following module is marked as installed in the core.extension configuration, but it is missing:
threejs_editor

Searching for threejs_editor on drupal.org or Google will give you some very, very small clues as to where the problem is located.

Steps to reproduce

Install Threejs field 3d Object 1.0.2 on a Drupal 9.5.7 running php 8.1.16. Wait some time. Do a composer update.
Threejs field 3d Object is updated from 1.0.2 to 1.0.4.

Try to update using the Drupal UI:

Missing or invalid module
The following module is marked as installed in the core.extension configuration, but it is missing:
threejs_editor

Drupal will provide you with some very vague and complicated steps to get out of this sorry situation.

Proposed resolution

I searched for threejs_editor on Drupal.org and Google and found out it was probably part of the Threejs field 3d Object module.

Then I downloaded 1.0.2 and looked at the source. Yes! threejs_editor existed back then!

I downgraded to 1.0.2 using
composer require 'drupal/threejs:1.0.2'

I then uninstalled the module using Drupal's UI (/admin/modules/uninstall).
Yep, all my 3D content - not much - was deleted.

composer require 'drupal/threejs:^1.0' installed 1.0.4

Upgrade will now run - but with a warning: orphaned value .

A sorry state of affairs, but way better than not being able to upgrade anything at all.

Remaining tasks

I'm not sure if the brave maintainers of Threejs field 3d Object can do anything to help people in a situation like mine.

The Drupal module system is frail and fickle and error reporting is inadequate and may never get fixed Display backtrace for logged throwables on log message details page Fixed .

I'm just dumping this experience here hoping to save other people some wild goose chases.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇩🇰Denmark Steven Snedker

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Steven Snedker
  • 🇫🇷France lazzyvn paris

    Yes, I just removed sub module threejs editor. You can downgrade 1.0.2 and remove threejs editor sub-module and update 1.0.4 later. Or you can wait for the next version 1.0.5, I will bring threejs editor back

  • 🇩🇰Denmark Steven Snedker

    Do you know if there's a correct way to remove submodules from your module?

    ChatGPT has this suggestion which to me sounds right on:

    If another user has not uninstalled one of your submodules and updates to the new version of your module that no longer includes that submodule, they will indeed get a fatal "submodule not found" error.

    To prevent this error from occurring, you can add an update hook to your module that checks for the presence of the submodule and uninstalls it if it's found.

    Here's an example of how you can do this:

    Create a new file in your main module's directory called my_module.post_update.php.

    In this file, create a function that checks if the submodule exists, and if it does, uninstalls it. Here's an example:

    function my_module_remove_submodule() {
      $submodule_name = 'submodule_to_remove';
      if (\Drupal::moduleHandler()->moduleExists($submodule_name)) {
        \Drupal::service('module_installer')->uninstall([$submodule_name]);
      }
    }
    

    In this example, replace submodule_to_remove with the actual name of the submodule that you're removing.

    In your main module's .info.yml file, add the following line:

    post_update: my_module_remove_submodule

    This tells Drupal to run the my_module_remove_submodule function when the module is updated.

    Now, when a user updates to the new version of your module, Drupal will automatically check for the presence of the removed submodule and uninstall it if it's found, preventing the fatal "submodule not found" error.

    God bless ChatGPT!

    The core developers have been discussing how to make the module system less fickle for years and years 🐛 Moving modules breaks system Active .

    But until they make the system more robust, I fear it's up to us to jump through these hoops in order not to break stuff.

    Thank you for your work on the Threejs field 3d Object module.

  • Status changed to Fixed 8 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024