Problem/Motivation
More or less everywhere we take an array of $messages as a method argument, we pass it not only not only TranslatableMarkup[], in practice, but also string[] this seem to happen most in in tests. The other case where we do this is when add validation results from exceptions.
We don't add want developers to create validation results that are not translatable. The only time where this should happen is when validation results are being create from throwable. in that case they won't be translatable.
Proposed resolution
We should make it easy to make it obvious that all validation results should translatable exception when created from exceptions
- Add
\Drupal\package_manager\Event\PreOperationStageEvent::addErrorFromThrowable - Add
\Drupal\package_manager\ValidationResult::createErrorFromThrowable - Change `\Drupal\Tests\automatic_updates\Traits\ValidationTestTrait::createValidationResult` to use translatable strings
- Replaces all places where we send untranslatable to
\Drupal\package_manager\ValidationResult::createError or \Drupal\package_manager\ValidationResult::createWarning, \Drupal\package_manager\Event\PreOperationStageEvent::addError or \Drupal\package_manager\Event\StatusCheckEvent::addWarning - In places where we add validation results from throwable(exceptions mostly) use
\Drupal\package_manager\Event\PreOperationStageEvent::addErrorFromThrowable
Remaining tasks
1,2,3 are done. 4 and 5 need to be done
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | Screen Shot 2022-12-13 at 2.53.59 PM.png | 591.57 KB | wim leers |
| #24 | Screen Shot 2022-12-13 at 2.38.41 PM.png | 656.33 KB | wim leers |
| #18 | Screenshot 2022-11-25 at 1.50.36 PM.png | 1.74 MB | kunal.sachdev |
| #18 | Screenshot 2022-11-25 at 1.49.44 PM.png | 1.75 MB | kunal.sachdev |
Issue fork automatic_updates-3312619
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
traviscarden commentedComment #6
tedbowI think maybe it is only in tests. We should fix that rather than updating the comments for bad practice. All the user facing errors and warning should be tranlable.
I have created another MR to fix the occurences
I have started it with 2 examples but someone else can take this over
Comment #7
tedbowAlso regarding the overhead this would create I checked core and t() is used all the time in core. Since this module is headed for core I think it is fine to do this.
Comment #8
tedbowActually so I could be wrong
In
\Drupal\automatic_updates\Validator\StagedProjectsValidator::validateStagedProjects()we actually doso this is non-test code that adds uses a non-translatable string. and this will be passed on to `\Drupal\package_manager\ValidationResult::createError`
Comment #9
tedbowIf it is only the case that we use non-translated string if we are passing on exception messages we could add
PreOperationStageEvent::addException(\Exception $e, $summary = NULL);and
ValidationResult::createErrorFromException(\Exception $e, $summary = NULL)so can more clearer that when you are not just passing on an exception message you need to provide translatable strings.
Comment #10
traviscarden commentedI have no concerns with that in principle, @tedbow. I just suggest that we do our best to follow any precedent already in Core in terms of the details, such as using static methods and what to name them.
Comment #11
tedbowComment #13
tedbowComment #14
wim leersShouldn't this be tagged
core-mvp? AFAIK translatability is one of the core gates: https://www.drupal.org/about/core/policies/core-change-policies/core-gates (although I don't see it listed? 🤯)Comment #15
tedbowComment #16
tedbowComment #17
kunal.sachdev commentedComment #18
kunal.sachdev commentedThe test \Drupal\Tests\package_manager\Kernel\StagedDBUpdateValidatorTest fails now if I try to use PluralTranslatableMarkup in \Drupal\package_manager\Validator\StagedDBUpdateValidator
.
but If I don't use PluralTranslatableMarkup and directly assign value then tests pass
Comment #19
wim leersTo figure out what's going on in #18: put a breakpoint in
Connection::__sleep()and observe what is calling it.Comment #20
kunal.sachdev commentedSo, actually problem is that if I have xdebug on and I don't even use any translation methods than all tests are failing with same error.
Comment #21
kunal.sachdev commentedComment #22
wim leers#3320782: xdebug being enabled causes tests to fail without clear indication that it is the problem just was a massive distraction because merely enabling xdebug caused every test method in that class to fail! Bumped that to in #3320782-7: xdebug being enabled causes tests to fail without clear indication that it is the problem.
Taking this over because after ~45 mins of debugging we still hadn't found the root cause. This is definitely very tricky!
Comment #23
wim leersHuh, even with #3325522: Automatic Updates & Package Manager should use DependencySerializationTrait when needed applied, the
Connection::__sleep()exception is thrown.I spent hours today on debugging this. I even debugged PHPUnit step-by-step. It must be related to some global state because
makes it fail in a different way.
If I add an early
return [];toConnection::__sleep(), it'll instead try to serializeContainerBuilder, and if I do the same thing there, it's aClosure… 😬😬😬😬Comment #24
wim leers🫣 I had to resort to modifying
vendor/phpunit/phpunit/src/Util/PHP/Template/TestCaseMethod.tplto make me able to debug__phpunit_run_isolated_test(), where thecall seems to have been causing this problem.
→ this means that some test is failing and
$resultcontains a failed PHPUnit assertion, which is why PHPUnit will try to generate helpful error output for it, including the stack trace. That stack trace in turn at some point contains a DB connection …To prove this, I had to painstakingly debug
phpunit's template-based test runner logic (see start of this comment), which eventually led me to …Stage. If I addpublic function __sleep() { return []; }to it, I get a helpful error output instead of the virtually impossible to debug error message that @kunal.sachdev showed in #18:Where exactly is that DB connection then? Glad you asked. That too took a lot of time to understand. Heck, what's worse, even if you modify
Connection::__sleep()to just return the empty array, there's another! Then it's this dependency chain:Stage→file_system(FileSystem) →container.channel.file(LoggerChannel) →current_user(AccountProxy) →event_dispatcher(ContainerAwareEventDispatcher) →container. If you fix that one, you're faced with a serializedClosure, which … PHP simply does not support.So, in a way,
\Drupal\Core\File\FileSystemis to blame. And many others. But …⚠️ The reason that this was "never before" a problem: #3307611: Create a validator to add a warning if updated extensions have database updates added
Stage $stageas a parameter to\Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase::assertStatusCheckResults(), and we simply haven't had to debug this before.Let's make sure not a single other soul on this project ever has to spend another minute on this nightmare: https://git.drupalcode.org/project/automatic_updates/-/merge_requests/54...
This means @kunal.sachdev (or somebody else) can now continue this issue, because now there are sensible test failures:
Comment #25
omkar.podey commentedComment #26
omkar.podey commentedComment #27
wim leers🥳
Comment #28
tedbowNeeds works for 1 point about an unrelated(I think) change
Comment #29
wim leersAgreed with @tedbow's concerns. We need to revert the precision in the messages and the function signatures, because it's not accurate. I think it was introduced to be able to meaningfully use
PluralTranslatableMarkup, but until #3253828: Use static analysis to detect new update functions, to reduce false positives in StagedDBUpdateValidator lands, that is premature. 😅Comment #30
omkar.podey commentedComment #31
omkar.podey commentedComment #32
wim leersNeeds work for a bunch of incorrect formatting/indentation cases 😅
Comment #33
omkar.podey commentedComment #34
omkar.podey commentedComment #35
omkar.podey commentedComment #36
omkar.podey commentedComment #37
wim leers@omkar.podey: you only fixed the 2 formatting problems that I provided suggestions for in https://git.drupalcode.org/project/automatic_updates/-/merge_requests/54.... There's 4 that I did not provide suggestions for, that still need to be fixed 😅
Comment #38
omkar.podey commentedComment #39
wim leersFound some problems with the use of the
$summaryparameter on\Drupal\package_manager\Event\PreOperationStageEvent::addError(), but that's a pre-existing problem. Tagging but that's for @tedbow to decide/sort out.Comment #40
tedbowNeeds work for 7.4 failures. Still reviewing
Comment #41
tedbowComment #42
wim leers@tedbow: Did you forget to mark this as needing review?
Comment #43
omkar.podey commentedlooks good to me
Comment #44
wim leersComment #45
tedbowAssigning to myself to commit when tests pass
Comment #46
tedbowThanks everyone 💪🎉!