Review main Merged

80104[BUGFIX] Harden Extbase LazyLoadingProxy

Torben Hansen CR +2 V +2 Easy +13 −8 updated 07/25/23, 06:59

Commit message

When a domain model object has a lazy loading property (e.g.
relation to another domain model object), the
`AbstractGenericObjectValidator` may fail validation the
domain model, if the database record for the related object
has been deleted.

This change fixes the problem by adding a null safe operator
to the `$realInstance` variable in the magic `__get` call
in LazyLoadingProxy. The return type for `_loadRealInstance`
has been adapted, since the function actually can return
`null`. This allows the removal of an entry in the phpstan
baseline file.

Additionally a todo in `AbstractGenericObjectValidator` has
been removed, since the function actually supports lazy
loading proxies as the initial error shows.

Review

  • Code review CR +2 Done
    • Nikita Hovratov +2
    • Oliver Klee +1
    • Alexander Schnitzler +1
  • Verified V +2 Done
    • Nikita Hovratov +2
    • Oliver Klee +1
    • Alexander Schnitzler +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 2326

Show 1 earlier messages
  1. Torben Hansen uploaded patch set 1 07/20/23, 18:06

  1. core-ci voted on patch set 1 V +1 07/20/23, 18:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44359

  2. Oliver Klee commented on patch set 1 07/20/23, 19:13

    Can we cover this case with a test?
  3. Alexander Schnitzler commented on patch set 1 07/21/23, 06:06

    LazyLoadingProxy.php:140

    What kind of objects are to be expected here? Usually, referenced objects are an instance of DomainObjectInterface, which is covered above.
  4. Torben Hansen commented on patch set 1 07/21/23, 06:40

    LazyLoadingProxy.php:140 Reply

    There is actually no object here, since the referenced object is deleted/hidden. `$this->_loadRealInstance()` actually return `null` in this case.
  5. Torben Hansen updated the commit message in patch set 2 V +1 07/21/23, 06:41

  6. Alexander Schnitzler commented on patch set 1 07/21/23, 06:42

    LazyLoadingProxy.php:140 Reply

    Shouldn't we simply return null then?
  7. core-ci voted on patch set 2 V +1 07/21/23, 06:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44366

  8. Torben Hansen commented on patch set 2 07/21/23, 06:55

    LazyLoadingProxy.php:140 Reply

    Yes, we actually do with the null safe operator. But I'm also fine adding an earlier check.
  9. Alexander Schnitzler commented on patch set 2 07/21/23, 07:05

    LazyLoadingProxy.php:140 Reply

    That's not what I meant but as discussed in private, we leave it as is. The risk of breaking something unintentionally is too high.
  10. Alexander Schnitzler voted on patch set 2 V +1 CR +1 07/21/23, 07:05

  11. Torben Hansen commented on patch set 2 CR -1 07/21/23, 07:08

    On it...
  12. Alexander Schnitzler commented on patch set 2 07/22/23, 06:09

    Reply

    Are you still on something or did you forget to remove the -1?
  13. Torben Hansen uploaded patch set 3 CR +1 V +1 07/22/23, 10:42

  14. Torben Hansen commented on patch set 3 07/22/23, 10:47

    Reply

    Done

    Reply

    Added a test.
  15. core-ci voted on patch set 3 V +1 07/22/23, 10:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/44413

  16. Oliver Klee voted on patch set 3 V +1 CR +1 07/23/23, 04:51

  17. Oliver Klee commented on patch set 3 V 0 CR 0 07/23/23, 04:52

    LazyLoadingProxyTest.php:82

    I propose we also add a second test (or use a data provider) with a non-zero UID that does not exist (because the 0 makes sense to catch early).
  18. Torben Hansen commented on patch set 3 07/23/23, 17:37

    LazyLoadingProxyTest.php:82 Reply

    The test does not fetch data from persistence since dataMapper is not involved (any UID provided will not have an effect), so I think it is fine if we just ensure, that the LazyLoadingProxy does return `null` instead of throwing an exception as it did before.
  19. Oliver Klee commented on patch set 3 V +1 CR +1 07/23/23, 17:40

    LazyLoadingProxyTest.php:82 Reply

    Ack
  20. Alexander Schnitzler commented on patch set 3 V +1 CR +1 07/25/23, 05:49

    Can you do me a favor and tag this patch with "extbase"?
  21. Torben Hansen wrote 07/25/23, 06:18

    Topic set to EXT: extbase
  22. Torben Hansen wrote 07/25/23, 06:18

    Topic EXT: extbase removed
  23. Torben Hansen wrote 07/25/23, 06:18

    Topic set to extbase
  24. Nikita Hovratov voted on patch set 3 V +2 CR +2 07/25/23, 06:47

  25. Nikita Hovratov merged patch set 4 07/25/23, 06:59