Problem/Motivation

Note: This only happens in tests. It was introduced here:

#521838-78: Clean up drupal_get_schema_versions() and commited in #521838-91: Clean up drupal_get_schema_versions() with the awesome comment "The patch looks fairly harmless (which probably means it will break everything ;))."

- drupal_get_schema_versions() caches the schema for all enabled modules.
- A parent test site has usually modules enabled like 'block' or 'node', but as the .install file for those is not loaded, drupal_get_schema_versions() returns array() for those.
- Therefore in system_install() when the module_list() is reset, but drupal_get_schema_versions() is not, the next time drupal_get_schema_versions() is called the wrong schema is returned. And therefore the wrong schema is recorded in the database.

This however happens just for the first test method in a test class, because as the .install files have been loaded the next time drupal_get_schema_versions() magically works (as once loaded functions don't disappear)!

Proposed resolution

- Reset the drupal_get_schema_versions() static in system_install(), which is fine as it is _just_ called afterwards again anyway (in drupal_install_system).

Remaining tasks

- Create patch

Comments

Fabianx created an issue. See original summary.

fabianx’s picture

Status: Active » Needs review
StatusFileSize
new898 bytes
new1.36 KB

Here is the patch and test. I decided to add this to the existing test method to make the test explicit.

The last submitted patch, 2: 2759899-2--tests-only.patch, failed testing.

fabianx’s picture

I double checked that this is not a problem in D8 both by caching the setUp(), which revealed the bug in D7 and by porting the --tests-only patch over to D8.

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

That looks very good to me.

I'm going to mark this RTBC since I know it's blocking another issue. I'm not sure I understand your reasoning for putting it in an existing test method though... Since the test relies on being the first test method in the class, I would think a dedicated test method would work a little better for that? Because then we could be very explicit (via a code comment or the method name) that it always has to be first... right now that info is sort of there in the code comment but it gets a little overshadowed by all the other things around it, and I can imagine someone not noticing that later and adding a method that happens to run before it.

fabianx’s picture

StatusFileSize
new1.71 KB
new1018 bytes
new1.48 KB

Hmm, I wanted to save on performance, but that is a very good point.

Changed it like that, but leaving at RTBC as I only moved around code.

The last submitted patch, 6: 2759899-4--tests-only.patch, failed testing.

stefan.r’s picture

Issue tags: +Pending Drupal 7 commit

Nice! This only affects tests (when module_list()/drupal_get_schema_versions() are already populated), and fixes a regression introduced 6 years ago :)

  • stefan.r committed 3c6803f on 7.x
    Issue #2759899 by Fabianx: drupal_get_schema_versions() does report...
stefan.r’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Committed and pushed to 7.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.