[development] important reminder: do not use API functions in update code

Gerhard Killesreiter gerhard at killesreiter.de
Tue Dec 4 16:14:29 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gábor Hojtsy schrieb:
> On Dec 4, 2007 3:29 PM, Gábor Hojtsy <gabor at hojtsy.hu> wrote:
>> Take system_update_6027 for example, which we try to fix at
>> http://drupal.org/node/197500 .
>>
>>  - it calls _block_rehash() (note the underscore, not even a public
>> API function!)
>>  - _block_rehash() uses drupal_save_record(), which uses the most up
>> to date schema from system_schema()
>>
>> Now what happens if the schema is changed in a later update in Drupal
>> 6? (ie. > 6027 but < 7000). Well, system_update_6027() becomes broken,
>> because its _block_rehash() call tries to use the latest schema (as in
>> after all Drupal 6 updates are run), but all Drupal 6 updates are not
>> run yet.
> 
> A similar example is system_update_1005() which is still in
> system.install in the name of letting enterprising folks try to update
> their 4.7 sites to 6.0. Well, it uses some API functions, namely:
> 
>   _node_type_set_defaults
>   node_type_save
>  cache_clear_all
>  system_modules
>  menu_rebuild
>  node_types_rebuild
> 
> (db_ functions and variable_ functions are mostly taken to be usable
> in updates).
> 
> So guess which one of the above breaks in a Drupal 6. Out of pure
> luck, only menu_rebuild() (at least in my testing), as at
> system_update_1005(), the menu system is far from being in the state
> where it is expected in Drupal 6.
> 
> So why isn't this a critical bug? Well, this is in pre 5.0 update
> code, and we officially only support updates from 5.x. So why are pre
> 5.x update functions still in Drupal 6? Nobody suggested to remove
> them yet (although we removed pre 4.7 update code). Let's discuss!

I am in favour of dropping the code for version-hopping updates. It has
always been a PITA to maintain it. If we leave it in, we need to fix it,
though. Let's simply remove it.

Cheers,
	Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHVXzlfg6TFvELooQRAkG6AKDAV7EhHqQmNarlME3uCDDSstwzeACgioV8
4hDrF+o4oonafUYu603muqM=
=8kkY
-----END PGP SIGNATURE-----


More information about the development mailing list