The one thing with the Features modules that really makes me nervous is that is automatically applies updates when I install and updated features module. This can turn very bad, especially if the update requires additional modules to be installed as well. Then there is a big chance the site will become unusable if those modules are not installed before the feature update.

Features is warning me about missing dependencies so that i don't enable them before those modules are installed, but how come it isn't checking these dependencies before it happily tries to apply all the settings in enabled features when I install updates?

Personally I would prefer if Features notify me about that a feature module has been updated, then I can go to the manage page and manually click apply changes after being able to review that everything is ready to go.

Comments

tsvenson’s picture

Title: Dependencies are not checked before an updated feature is applied » Dependencies are not checked before an updated feature is automatically applied

I have been thinking a bit more about this problem. I really like how Features can help and make development/deployment easier, but its habit of automatically applying changes when I upload a new version is quite scary.

How come it does it this way and not allow me to do this manually?

Anyhow, my suggestion to solving this is:

  • Detect the new version and display an message, with link to admin page, for users with permissions to administrate features so they can trigger the update. Do not automatically apply them!
  • Make it possible to select several updated features modules to be updated at the same time.
  • Add an option to put the site in Maintenance Mode before the update. Then set it back to live after the updates are applied

Something like this would make working with and deploying updated features a much less scary operation.

At the same time it would also let me update several modules at the same time, which will be very handy if they have dependencies on each other.

irakli’s picture

Status: Active » Closed (works as designed)

I am sorry but I don't think you really understand what Features module is and how it works. Features module is not a deployment tool, it's a way to manage configuration from code. So when you create a Feature, configuration is in the code. Therefore "immediately applies changes" is not a completely correct statement.

If you don't have your feature overriden, configuration is served from code, therefore deploying new code changes configuration immediately - that's to be expected. If you do have configuration overriden, it actually does not change configuration immediately, so your statement is not always true.

Either way, you should not update your feature module if you don't want changes to go live right away, it beats the purpose and the whole idea of the module (as well as CTools module, which Features frequently uses).

tsvenson’s picture

I do understand the part about managing configuration/change in code. However, when reading the project page it also says:

as a way to manage changes between development, staging and production sites

As a site builder it is very easy to see how useful this module can be to make deployment of new features on a live site easier and quicker. As well as rolling out updates to them.

To be hones, limiting the scope of this module to just "managing it in code" almost seams like it is only half complete to me.

I fully understand the advantages of having configuration in code, especially when you collaborate with other developers on the same site.

The project page also talks about building features such as blog, pressroom, image gallery and so on. But to use those you need to deploy them on a site, don't you? Plus that as we know sites are constantly changing, features are added, changed or removed.

I believe that with just a few additions, such as the ones I suggest in this issue Features can take the next step and become a great deployment tool as well. Its almost there, using the checklist I published in the post you commented on makes it somewhat controllable for that purpose.

I also believe that if such functionality would be added it would also make it much easier for developers and site builders (click monkeys like me) to collaborate even better and more productive.

fabianx’s picture

Hi Thomas,

As already written here:

http://www.drupalmill.com/comment/127#comment-127

again in short form:

Many companies use features for deployment, but it is not an import / export tool.

You are suggesting a fundamentally different approach, which would break all existing workflows.

Besides how do you want to review if the new feature is "okay"?

* Okay, it overrides the really important client changes the client did, which will make him really unhappy - But you can't see this on the site.

* Okay, all dependencies seem correct. - Too bad this particular dependency was not auto-detected and your developer forgot about it.

But what you are thinking of is:

* I have pressroom feature module / other contrib module.

* I installed it on my site.

* Third-Party updated pressroom feature / other contrib module.

* I want to update the feature / the other contrib module on my site.

* This feature / the otehr contrib module now needs more dependencies.

You are right that you are not warned that dependencies are missing, but this is not specific to features, but rather is valid for all contrib modules.

But if third party or contrib author is clever, he adds a status message to status report that this feature, this module now needs that and that module.

Or even already in update.php, like seen on drupal planet just some time ago:

http://www.koumbit.org/en/articles/using-hook-update-non-database-relate...

You could now argue that this kind of info should be there automatically, but this has nothing to do with features.

Again as a site builder you can prevent this easily by checking for your new dependencies in via hook_update_N(), because you are the only one that knows.

So if you want to see this fixed, add bug to core and drush or whatever deployment tool you use.

They can change this, features can't.

Best Wishes,

Fabian

tsvenson’s picture

Hi Fabian,

Sorry for the delay in responding, have been a busy week for me.

Thanks for your clarifications, they are most enlightening to me and have helped me better understand how Features work, as well as adjust my workflow using it.

However:

You are right that you are not warned that dependencies are missing, but this is not specific to features, but rather is valid for all contrib modules.

That other modules doesn't properly check this is, in my view, not an excuse for Features not to do it. Especially considering that dependencies are checked for not enabled features.

As you say, Features configurations are run from code, with one important exception - dependency modules will be written to the database as enabled no matter if they exist or not for enabled feature modules.

In my experimenting this has rendered my sites unusable and forced me to manually edit the database.

This could easily be avoided if Features run the same test for enabled modules as it does on disabled. If it doesn't find the module the feature requires it should warn users with permission about it. Then I simply have to upload that module and everything will work as planned.

That would at least prevent the risk of rendering the site unusable in most cases.

I am a site builder, not a coder, so your suggestion that I add my own check for this is not an option. And why should I when Features clearly already has this possibility for disabled features?

Is there any good reason why this is only done for disabled features?

fabianx’s picture

Hi Thomas,

The reason is that this would have to be fixed in core and/or drush, because features cannot do much to warn you, because the old code is already gone.

So if the site is broken, it is broken and no warning can be spit out.

So this is not workable or easy.

It is easy as long as the module is disabled, because then drupal will refuse to enable it, if dependencies cannot be satisfied, but what should it do, if dependecies go missing?

* Disable the module?
* Warn loudly about it?
* Hope that nothing breaks?

This is really something the person that is doing the upgrade needs to take care of by either tools or manual checking. Or the module author.

Features _could_ integrate hook_requirements however to check for missing modules, but it won't help in the "my site is totally broken" case.

Best Wishes,

Fabian

tsvenson’s picture

As I have said before I am not a skilled coder, but I had a look at the Features code and found this function.

<?php
function features_install_modules($modules) {
  module_load_include('inc', 'features', 'features.export');
  $files = system_rebuild_module_data();

  // Build maximal list of dependencies.
  $install = array();
  foreach ($modules as $name) {
    if ($file = $files[$name]) {
      $install[] = $name;
      if (!empty($file->info['dependencies'])) {
        $install = array_merge($install, _features_export_maximize_dependencies($file->info['dependencies']));
      }
    }
  }

  // Filter out enabled modules.
  $enabled = array_filter($install, 'module_exists');
  $install = array_diff($install, $enabled);

  if (!empty($install)) {
    // Make sure the install API is available.
    $install = array_unique($install);
    include_once DRUPAL_ROOT . '/' . './includes/install.inc';
    module_enable($install);
  }
}
?>

From what I understand it works like this:

  1. Read the dependency array from the feature modules .info file
  2. Filters out those dependencies that already are enabled
  3. Runs install on those that are not enabled.

If I have understood this correct, wouldn't it then be possible to add a check before step 3 where it also checks if the module is actually available (installed)?

When you look at the module list, for some modules there is "missing" in red when a module depends on a another module that isn't installed and the checkbox is greyed out so it can't be checked.

sinasalek’s picture

Interesting discussion :)
There is something that i don't understand, features overrides and imports configuration to db from file when enabled and then changes them again when updated rightaway. So when we update a feature even if that feature changes many things nothing should change unless we update it. Even if what feature depends on new missing modules in its latest version nothing should break before that feature update the db with new changes.
Isn't it how features work and how it detect and compares the changes with new modifications ?
If it's right then even if feature change its dependencies before updating the db and fails to update, everything should work just fine.