Why is hook_schema() called twice? I'm working with entities and, in trying to troubleshoot another issue, I noticed that hook_schema() is called twice each time the module is installed. This happened even with a bare bones test module containing only a hook_schema() definition. My questions are:


Is it normal for hook_schema() to be called twice on module installation?
Why would hook_schema() be called twice on installation?
It seems to be normal. Looking at the hook_schema documentation, you see that it is invoked in drupal_get_complete_schema() in includes/bootstrap.inc and in drupal_get_schema_unprocessed() in includes/common.inc. The main difference is that the latter does not invoke hook_schema_alter() after the hook_schema is invoked. The first of those functions seems to be called on practically every page load. The second function is called from drupal_install_schema() during the module install process.

Concluding, looking at the code it seems to me that:


It is normal
It happens because during installation, Drupal needs the un-altered schema definitions