Needs work
Project:
Drupal core
Version:
main
Component:
batch system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 May 2017 at 13:55 UTC
Updated:
30 Jan 2023 at 21:25 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #8
jungleShould we just check the existence of the file or throw an exception if it's not found. In batch.inc it does not throw an exception
Comment #9
larowlanI think we should retain the existing functionality
Can we use
assertso developers can see their error, but it doesn't impact site users?Comment #10
jungleThanks, @larowlan, using
assertis good to me. Another question.BatchBuilder:
batch.inc:
include_once $filename;vsinclude_once \Drupal::root() . '/' . $batch_set['file'];,$filenameinsetFile()expects an absolute path,$batch_set['file']in_batch_finished()expects a relatvie path. Should we unify them?Comment #11
larowlanYes, because I think as it stands, this will break
Comment #12
jungleis_file()Returns TRUE if the filename exists and is a regular file, FALSE otherwise.I doubt
include_once \Drupal::root() . '/' . $batch_set['file'];never gets executed. (batch.inc's path is core/includes/batch.inc.)For example:
is_file('core/foo/bar.inc');it might lookupcore/includes/core/foo/bar.inc. It can not be TRUE in general.So I propose to support both the absolute path and the relative path. See the patch, then we don't need to worry broken the existing sites.
(Pending change the title/scope)
Comment #13
jungleSelf-review:
would be better adding a description to
assert().Comment #14
pratik_kambleComment #15
daffie commentedA quick review:
You are missing the is_file() on this line.
Comment #16
jungleThanks for your quick review, @daffie!
Addressing #15.1, and tagging "Needs tests"
Comment #17
jungleAdding tests.
Comment #19
jungleFixing #17
Comment #20
jungleTagging Bug Smash Initiative
Comment #21
acbramley commentedMissing the is_file call around the second path.
The fact that this didn't fail tests maybe indicates missing test coverage?I don't think that's the case.Spelling and camel casing need fixing here
I think these could do with some re-wording.
Fixed these up myself :)
Comment #22
acbramley commentedMissed the new fixture file 🤦♂️
Comment #23
jungle@acbramley, many thanks for reviewing and correcting.
Comment #25
jungleFixing #22/#24
Comment #26
jungleChanging to $this->expectException(AssertionError::class);
Comment #27
daffie commentedPatch fails testbot.
Comment #28
jungleThanks, @daffie!
Should be $filename = $batch_set['file']; my bad.
Comment #29
daffie commentedAs far as I can see there is no testing added for the change to the function
_batch_finished().The added testing for
BatchBuilder::setFile()look good to me.@jungle: "My bad" happens to every programmer. :)
Comment #30
jungleThanks @daffie!
No existing test i could find to cover _batch_finished(), that means, no test coverage to _batch_finished() as i know. And there is an issue #2875151: [META] Implement Batch API as a service.
Meanwhile, per the issue title, touching _batch_finished() is not in scope. So I am reverting the changes to _batch_finished() keeping it untouched.
Comment #31
daffie commentedNot the solution that I expected, but is ok too.
The added solution looks good to me.
There is testing added for the solution.
For me it is RTBC.
Comment #32
larowlanFrom what I can see
\_batch_processalways appends the `\Drupal::root` to the passed file.So if we support the option with a full path, that will end up in \Drupal::root being appended twice.
I.e. I think the batch handler only supports relative paths.
Thoughts?
Comment #33
jungleThanks @larowlan!
Code snippet from
\_batch_process().is_file()makes sure$current_set['file'])is a valid file path.include_once $current_set['file'];should work for both relative path and absolute path.Using
BatchBuilder,include_onceis unnecessary here in\_batch_process()and other_batch_*functions. But it's no harm if it does.\Drupal\Core\Batch\BatchBuilder::setFile()supports both relative path and absolute path which should be fine and good, IMO.In all, I am going to try removing prepended
\Drupal::root()in\_batch_process()so that full path inBatchBuilder::setFileshould work.Comment #34
daffie commentedIf we are going to do this then we should add support for absolute and relative paths. Now we are changing support for absolute paths with support relative paths. To me it would be better to support both. If we cannot add testing for it, then so be it. In the file core/includes/batch.inc we have 2 instances of it. The first on line 277 and the second on line 451. Lets fix it for both.
Comment #35
andypostAny reason to support absolute path? it looks insecure
Comment #36
jungleAlmost all
_batch_*functions in batch.inc are missing tests coverage. So re-uploading #30 for review. For here, only If there is an existed test to modify, I am trending to add testing for it.Maybe it's fine to support absolute path in BatchBuilder, not sure. No idea to the security.
Comment #38
jungleA known random fail.
Comment #39
daffie commentedHi @jungle: The change that you make in the file core/lib/Drupal/Core/Batch/BatchBuilder.php, can you make the same change in the functions: _batch_process() and _batch_finished() in the file core/includes/batch.inc?
Comment #40
jungleHi @daffie, do you mean this -- see the patch?
Comment #41
daffie commented@jungle: Yes, that is the change I was looking for.
For the changes in core/lib/Drupal/Core/Batch/BatchBuilder.php and core/includes/batch.inc there is no testing added, because AFAIK we cannot test those changes.
For me we should support both absolute paths and relative paths.
Back to RTBC.
Comment #42
quietone commentedUpdated the IS.
Comment #43
alexpottI think these changes are out-of-scope and unnecessary. Widening the API to include any file is a security concern.
There is no need for this to be including the file already. Why is this change being made.
I've always been a bit dubious about the value of this change. PHP will error very nicely when you try to include a file that does not exist. The asserts are meaningless because if the file doesn't exist then PHP is going to fail and fail hard.
Personally I think we should close this as works as designed.
Comment #44
alexpottFurthermore, once all the operations and callbacks are static methods on classes - or we support services via the class resolver in the batch system then setFile() become meaningless because everything is being autoloaded.
Comment #45
jungleThanks @alexpott!
+1, setting to NR for closing this if applicable.
Comment #47
duneblI am not sure it is true, because here is the actual code:
If the file doesn't exists it will not be included and it will fail silently (except in the logs)... In my case, I spent too much time to understand that the batch process didn't occurs (looking at the progress bar, everything is fine but in fact it is not fine)
Comment #52
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.