backdrop-issues icon indicating copy to clipboard operation
backdrop-issues copied to clipboard

Document why the backdrop_install_schema('system') in system_install() is necessary

Open avpaderno opened this issue 2 years ago • 9 comments

system_install() calls backdrop_install_schema('system'), which is usually done from Backdrop core before installing a module.

Since this is an exception, a comment in the code should remember us that.

avpaderno avatar Feb 25 '23 11:02 avpaderno

OK, I really missed something. 😅 I guess that a comment like This must be explicitly done, or the tables won't be created. should suffice.

avpaderno avatar Feb 25 '23 12:02 avpaderno

I'm not sure extra comments are needed... It already says this creates tables.

ghost avatar Mar 01 '23 03:03 ghost

It does not say why hook_schema() is explicitly called in hook_install(), when it is not necessary for other modules. That is what the documentation for hook_schema() says.

The tables declared by this hook will be automatically created when the module is first enabled, and removed when the module is uninstalled. This happens before hook_install() is invoked, and after hook_uninstall() is invoked, respectively.

IMO, a comment saying that is an exception to the "general rule" should be added, at least to make that clear to developers who watch at Backdrop core code to write their own code. If that is not considered necessary, I am fine with that.

avpaderno avatar Mar 01 '23 09:03 avpaderno

Fair enough.

ghost avatar Mar 01 '23 09:03 ghost

The sentence I added (This must be explicitly done or the tables won't be created.) is probably too terse. The longer version could be:

Differently from other modules, The System module needs to explicitly call backdrop_install_schema('system') or its tables won't be created.

I open to suggestions. (English is not my first language nor my second one.)

avpaderno avatar Mar 01 '23 10:03 avpaderno

Differently from other modules, The System module needs to explicitly call backdrop_install_schema('system') or its tables won't be created.

I'm wondering why this explanation is needed? It is an interesting fact, but, as a developer, it probably won't change the way I do things. Knowing that hook_schema will be called before my module's install hook, on the other hand, is important and can change the way I create my code.

argiepiano avatar Mar 01 '23 14:03 argiepiano

I think that it makes sense to document in a comment when there is a departure from the normal way of doing things and where the reason might not be immediately obvious.

laryn avatar Mar 01 '23 18:03 laryn

The failing tests are not failing because of changes done in this PR. (I think I have seen those tests failing on other PRs too.)

avpaderno avatar Jun 25 '24 09:06 avpaderno

Differently from other modules, The System module needs to explicitly call backdrop_install_schema('system') or its tables won't be created.

How about:

As an exception from other modules, the System module needs to explicitly call backdrop_install_schema('system') or its tables won't be created.

izmeez avatar Jun 25 '24 21:06 izmeez