Problem/Motivation
This is when Garland is the site default, Seven is the admin theme, and I run a simpletest.
The Simpletest selection page is in Seven, the batch API page for progress bar is Garland, and the results page is Seven again. Just guessing, but I bet that's the case with all batch API, it uses the default or maintenance theme, not something to be blamed on simpletest.
Steps to reproduce
Proposed resolution
Remaining tasks
Determine if there is a problem with the theme and running cron manually. See #38.
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#82 | wrong-route-check-539022-82.patch | 685 bytes | mibfire |
#71 | wrong-route-check-539022-71.patch | 554 bytes | Zemelia |
#55 | run-cron-539022-55.patch | 671 bytes | marcingy |
#53 | admin_theme_unittests.patch | 2.98 KB | mthomas |
#51 | admin_theme_unittests.patch | 3.01 KB | mthomas |
Comments
Comment #1
yched CreditAttribution: yched commentedIt's been like that before Seven. Batch pages live at URL /batch. They are thus out of admin section, and use the regular frontend theme.
I'd tend to mark 'by design'.
Comment #2
yched CreditAttribution: yched commented#541148: Garland still used for all batch processes was marked duplicate.
Comment #3
Gábor HojtsyWell, maybe we need a way to identify admin initiated batches and user initiated batches then? Ie. have an /admin/batch path and a /batch path which would only be different in what theme they use but otherwise map to the same function. When a batch is to be executed from an admin page, the admin batch path would be used?
Comment #4
yched CreditAttribution: yched commentedI guess that's doable.
Then again, it would work only for admin theme vs main theme. There would still be a theme change if the batch is triggered from a page that uses a different front-end theme (rare case, I guess).
I'm wondering if the system_batch_page() callback can still initialize the page theme (i.e no theme call happened earlier on). Then batch_process() could just set $batch['theme'] = 'current_theme' and system_batch_page() would reuse that theme for the batch progress page ?
Another approach, now that jQueryUI is in core, would be to display batch progress in a jQ modal, which I always thought would be damn cool, and would somewhat sidestep the theme issue - but that's a lot more work...
Whatever the approach taken, I don't really have the time to look into it currently, any taker welcome :-/
Comment #5
dropcube CreditAttribution: dropcube commentedAn approach would be to save the current theme when
batch_process
is executed, and serialize it with the other process info. Then, retrieve the theme saved (the theme of the page that started the batch) and use it (setting the$custom_theme
global.
The attached patch implements this approach, and fixes the issue reported. The batch process page uses the same theme of the page that started the batch.
Comment #6
Gábor HojtsyWonderful. I'm not sure global's in the middle of functions are up to the current coding standards, but I love in this approach is that it is compatible with whatever theme switching the user had, so if there is section based theming, the batch will keep the same theme used for the section at hand, where she initiated a batch process.
Comment #7
yched CreditAttribution: yched commentedThanks for tackling this, dropcube !
Why 'theme_key' instead of just 'theme'. We don't suffix all our keys with '_key' ;-)
Comment #8
catch'theme_key' is already a global I think, can we use $GLOBALS['theme key'] instead?
Comment #9
dropcube CreditAttribution: dropcube commentedRe-roling the patch against HEAD. Now using $GLOBALS['theme_key'] and 'theme' in the batch info.
Comment #11
dropcube CreditAttribution: dropcube commentedI can't reproduce the bug reported by the bot. I can install Drupal, with the UI and with command line. Let's try with a fresh patch.
Comment #12
dropcube CreditAttribution: dropcube commentedComment #13
yched CreditAttribution: yched commentedPatch is OK - can't test right now, but if dropcube confirms it works on, say, simpletest pages, then I think he can freely set RTBC.
Comment #14
dropcube CreditAttribution: dropcube commentedYes, I confirm it works on simpletest pages. See screenshot.
Comment #15
yched CreditAttribution: yched commentedHm, sorry, last detail: we shouldn't display the toolbar on those pages. We don't want to invite the users to navigate away while the batch is running, could leave a site in an undecidable/broken state.
Comment #16
Gábor Hojtsy@yched: I'd think that would be a different issue. Opened #563562: Batch API pages should not show the toolbar.
Comment #17
yched CreditAttribution: yched commentedYou're right. RTBC.
Comment #18
webchickNice improvement!
Committed to HEAD.
Comment #19
dropcube CreditAttribution: dropcube commentedComment #20
dwwEither this fix doesn't work, or I'm doing something wrong in update status, but I'm not seeing this on a batch_process specified in the admin section (when you check manually for available updates using #597484-4: Use the Queue API to fetch available update data. Compare:
http://drupal.org/files/issues/597484-4.update_queue_api.fetch-manually-...
http://drupal.org/files/issues/597484-4.update_queue_api.fetch-manually-...
Any ideas? Maybe that patch is doing something wrong, but it sure appears that this fix isn't in place, even though I definitely have a clean install of HEAD I'm working from...
Thanks,
-Derek
Comment #21
dwwOkay, a little debugging later and I confirmed that the code in the patch is both in my copy of core, and being hit. Inside system_batch_page(), if I
dsm($GLOBALS['custom_theme'])
it's coming out "seven". However, it's *definitely* themed as garland, not seven. ;) It's 3:30am here, and I'm fried, but if anyone has a chance to further debug, that'd be lovely...Comment #22
dwwAhh, broken by #553944: Define hook_menu_get_item_alter() as a reliable hook that runs before the page is doomed. Setting $GLOBALS['custom_theme'] doesn't do any good anymore. ;)
Comment #23
sunyes, it's defined in the menu system now. Though I didn't know that $custom_theme doesn't work at all anymore. Which is a problem, because modules like http://drupal.org/project/switchtheme heavily rely on it. Either we re-open the other issue or we continue here, not sure.
Comment #24
sunBumping priority.
Comment #25
webchickSo the first thing we definitely need is a test here. :P Had we had one, we would've seen that #553944: Define hook_menu_get_item_alter() as a reliable hook that runs before the page is doomed broke it before that got committed.
Comment #26
David_Rothstein CreditAttribution: David_Rothstein commentedThough the lack of tests are somewhat at fault, it's mostly me :) I searched for all uses of $custom_theme throughout core while working on that patch at one point, but not recently enough to have caught the one introduced by this commit.
I'm somewhat consoled by the fact that the original patch that was committed here wouldn't have worked anyway :)... well, it worked fine with core, but a number of contrib modules would have conflicted with it and broken it, which is why we did #553944: Define hook_menu_get_item_alter() as a reliable hook that runs before the page is doomed in the first place.
Here's an initial start at a fix. This works, but does not come with tests (not sure off the top of my head how to write tests for the batch API, so deferring that for now). It involves more moving around of code than you might expect, because the theme is now set early in the page load, before the batch would otherwise be loaded from the database.
@sun: I think you may have a point. What we have in core now works fine for situations like this (where you are setting the theme for a particular page or set of pages) but does not work well for situations where you want to dynamically change the theme across the site. The overlay is another example of something that will run into problems here. I'll think about it a bit and reopen #553944: Define hook_menu_get_item_alter() as a reliable hook that runs before the page is doomed so we can make sure that capability gets added back ...
Comment #27
sunI'd be happy if some Batch API master could have a look at this patch.
Wrong indentation.
This review is powered by Dreditor.
Comment #28
yched CreditAttribution: yched commentedI'm just a bit confused by this comment:
I didn't follow the 'theme callback' thread, but I'm wondering in which cases the batch might be already loaded at this point ?
Other than that, patch looks fine.
Comment #29
David_Rothstein CreditAttribution: David_Rothstein commentedFixed the issue from #27 and also changed this from the previous patch:
to this:
because it's much cleaner - not sure what I was thinking the first time :)
@yched:
Yeah, I'm not 100% sure either, which is why I left it a little wishy-washy in the code comment. The theme callback runs very early (before hook_init is called), so I guess the only way it could happen is if someone loaded the batch in hook_boot() or something like that, which I suppose would be pretty rare.
I'm putting this at "needs review" for the testbot, but we still do not have a test included in the patch, so it's not yet ready in that sense.
Comment #30
sunI had to think twice what the "id" of a batch is. Maybe we should clarify that this is a auto-assigned serial column id in the db? hrm, that suggestion sounds silly... So perhaps rather, that this id usually contained in $_GET['id']?
We should return FALSE at the end of the function here.
I'd prefer to drop the second sentence here. This code runs when the active menu handler is executed, so it's clear that anything before it will run before it, and if there's something that loaded it already, then it simply won't be loaded again, so the "wishy-washy" comment (as you put it) has no point in itself ;)
I'm on crack. Are you, too?
Comment #31
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis sounds more like a feature request. Important, nonetheless.
Comment #32
yched CreditAttribution: yched commentedActually, since a first patch already got in, got broken by a later commit, then turned out to be flawed anyway, this is now technically a bug ;-)
Comment #33
sunThis is an annoying regression, but no totally critical bug - hence, changing tags, priority, and also assignment, because it seems like dropcube is no longer working on it.
Comment #34
David_Rothstein CreditAttribution: David_Rothstein commentedOK, this fixes the three points made in #30, and also adds a test.
As explained in the code comment, there doesn't seem to be a way to test this 100% directly, so I used a slightly indirect method - however, it works fine (in that if you run the test without applying the rest of the patch, the test correctly fails and therefore identifies the bug).
Comment #35
yched CreditAttribution: yched commentedCode is fine by me, sun's concerns were adressed.
drupalPost/drupalGet indeed loop through the batch redirects, and thus do not let tests 'see' the batch page. The workaround is smart and tests pass.
RTBC. Thanks David.
While people are looking at the batch progress page:
#563562: Batch API pages should not show the toolbar should be ready and needs someone to push the RTBC button.
#614826: Batch page should not display blocks could use some feedback on page rendering strategies.
Comment #36
webchickAwesome, thanks a lot! With tests, even. :D
Committed to HEAD.
Comment #38
douggreen CreditAttribution: douggreen commentedWe have the same problem with admin/reports/status/run-cron, which inherits the theme settings from admin_theme because of admin in path. This is a very simple fix, see attached patch, but for those just reading and not applying, the change is:
Comment #39
David_Rothstein CreditAttribution: David_Rothstein commentedUnless I'm missing something, Drupal does not have a variable called 'theme'... :) Also, I don't understand - why does it matter what theme is used during a cron run?
Comment #40
douggreen CreditAttribution: douggreen commentedGood catch, should be 'theme_default'.
It matters because what people do in hook_cron may very likely rely on the base theme. You might use hook_cron to prebuild cached pages. You might use hook_cron to send out emails that rely on your theme. You can use hook_cron to do anything, and certainly, you'd expect your theme overrides in the base to be called.
Comment #41
douggreen CreditAttribution: douggreen commentedAlso, you'll get different themes, running run-cron in admin and cron.php from cron, and is bound to cause problems. The point of the run-cron link is to run cron manually, not run it differently.
Comment #42
catchYeah for example search indexing does a full comment render which will invoke templates, so this needs to be the site theme. Looks good to me.
Comment #43
David_Rothstein CreditAttribution: David_Rothstein commentedCan this get a code comment explaining the reasoning here? I think it's probably non-obvious for someone looking at the code.
Also, this same issue exists in D6 as far as I know - so would be interesting to see if there are any real-world cases where this caused someone a problem :) But the examples in #40 do seem very realistic, especially the idea of sending out templated emails or that kind of thing.
Comment #44
douggreen CreditAttribution: douggreen commentedReally, a comment for this? We don't have comments anywhere else we set the theme. IMHO, the extra comment isn't worth it.
The real world example where this caused me pain is the templated emails.
Comment #45
douggreen CreditAttribution: douggreen commentedHere's the patch with the comment ... please feel free to edit the comment as you like.
Comment #46
catchAgree on adding the comment, less likely someone tidies this up later and breaks it again. Can't think of a better comment that wouldn't be a paragraph long, and this conveys the information we need, so re-rtbcing.
Comment #47
David_Rothstein CreditAttribution: David_Rothstein commentedYeah, I think the reason a comment is worthwhile is that this menu callback doesn't result in anything actually being displayed on the screen, so people would definitely wonder why we need to bother fiddling with the theme for it!
The comment looks good to me too.
Comment #48
Dries CreditAttribution: Dries commentedI'm not sure about this fix.
What happens when someone calls drupal_cron_run() from elsewhere? Shouldn't it be the task of drupal_cron_run() to set the proper theme? I'd like us to think about this some more.
Or, if a cron function depends on a specific theme, it sounds like it should be that cron function's responsibility to make sure it is set to be the active theme.
I also don't understand why search module would require a specific theme (per catch's example)
Comment #49
David_Rothstein CreditAttribution: David_Rothstein commentedI think by the time you get to drupal_cron_run() or later it is potentially too late - the theme may have already been initialized by someone else... and once it's initialized, Drupal doesn't exactly make it easy to undo that (http://api.drupal.org/api/function/drupal_theme_initialize/7), so without expanding this issue a lot I'm not sure if there's anything else that can be done.
Comment #50
catchhttp://api.drupal.org/api/function/comment_node_update_index/7
calls drupal_render()
drupal_render() calls theme()
If you are hiding labels or field values or whatever in your theme, you wouldn't want those showing up in your search index either. Same goes for indexing nodes - IMO node templates should be allowed to run.
Comment #51
mthomas CreditAttribution: mthomas commentedHere is a patch to simpletest.test to verify that this issue is fixed.
Comment #53
mthomas CreditAttribution: mthomas commentedOops, forgot to remove the first line. This is my first patch, all apologies. Resubmitting the patch.
Comment #54
attiks CreditAttribution: attiks commentedSubscribing, I'm facing similar problems: #981654: Use several themes during the same page request
Comment #55
marcingy CreditAttribution: marcingy commentedJust a reroll to head and to git. Moving to d8 as it needs to be fixed there first.
Comment #57
marcingy CreditAttribution: marcingy commented#55: run-cron-539022-55.patch queued for re-testing.
Comment #58
N20 CreditAttribution: N20 commented#29: batch-theme-fix-539022-29.patch queued for re-testing.
Comment #59
kscheirer#55: run-cron-539022-55.patch queued for re-testing.
Comment #61
Pancho// Use the same theme as the page that started the batch.
IMHO we shouldn't only use the same theme as the page that started the batch. We should rather really stay on the path of the page that started the batch, just the way install.php, update.php - or more generally Better Batch module - work.
We could and probably should also leverage modals using the new Dialog API.
Comment #62
yched CreditAttribution: yched commentedBatch progress in popups would totally be nifty.
I opened #1993518: Display batch progress in modals for this. Needs volunteers :-)
Comment #63
PanchoThanks, Yves, yes that'd be awesome!
Batches in modals don't completely supersede this issue, but that's where the music is playing.
We shouldn't forget to return here afterwards, though.
Comment #71
Zemelia CreditAttribution: Zemelia commentedWrong route name used in BatchNegotiator::applies method.
Patch attached.
Comment #78
quietone CreditAttribution: quietone as a volunteer commentedThe last patch, in #71, identifies an incorrect route in BatchNegotiator.php. I searched for duplicates of that didn't find any. I'll make an issue for this. I've made an issue for this, #3221633: BatchNegotiator tests for an invalid route. Added credit for Zemelia over there.
This was committed in Nov 2009, #36. It was then reopened, I think, to discuss a similar problem with the theme when cron is run manually. There is no commit related to that and I am not sure how to test it to determine if it still a problem.
Is this still a problem? Should this be closed, fixed, and a new issue opened to discuss the theme with cron or just closed?
Comment #79
LendudeDiscussed with @catch in #bugsmash and we agreed that manually running cron shouldn't be an issue any longer since that doesn't run in a batch anymore.
@quietone has opened a follow up for the one remaining issue that was raised here.
So moving back to 'fixed' since this was committed back in 2009.
Comment #81
mibfire CreditAttribution: mibfire commentedThere is an issue with "applies" method of BatchNegotiator class. This doesn't take the "system.batch_page.json" route into account. So for example while the default theme is used on the "system.batch_page.html" route the admin theme is used on "system.batch_page.json" route. Question is why "system.batch_page.json" route is not taken into account in the "applies" method? In my opinion this should be consistent through the whole batch process regardless of this is the batch page("system.batch_page.html") or the batch ajax calls("system.batch_page.json").
Also the following is how the theme is set for the batch at the beginning.
=>
So this should apply to the ajax calls too.
I created a patch for this issue.
Comment #82
mibfire CreditAttribution: mibfire commentedPls repoen the issue.