Issue Bug Closed

#106600findBy([ 'uid' ... ]) uses constrain 'pid' > it's not a dropIn replacement for findByUid() according to ChangeLog #100071

Christian Hackl 04/23/25, 10:23 updated 04/23/25, 18:54

Description

According to the changelog, the “magic” findBy methods are deprecated, which means, for example for a query:
@$this->myRepository->findByUid(55);@
you would now have to write:
@$this->myRepository->findOneBy([ ‘uid’ => 55 ]);@

However, the SQL query is not identical, as the new “findBy” / “findOneBy” methods take the “pid” into account and set it to “0” by default, i.e. the pid is also queried in the “constraint”. the old “findByUid” method has no “pid” query.

In my current case, it was enough to set respectStoragePage to “false” in my repository:
$querySettings->setRespectStoragePage(FALSE);

However, I don’t think this is the solution in every case, perhaps it would be possible to do exception handling for “uid”, e.g.
@if(isset($criteria[‘uid’])) {
$query->getQuerySettings()->setRespectStoragePage(false);
}@

or maybe you could add a flag to the methods?

In any case, this is not a dropIn replacement, so i think it should at least be mentioned / changed in the documentation:
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.3/Deprecation-100071-MagicRepositoryFindByMethods.html

or here:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/Extbase/Reference/Domain/Repository/Index.html

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 6

  1. Garvin Hicking commented and changed category status New Needs Feedback <span data-processor="relativetime" data-value="2025-04-23T10:36:07+00:00" > 04/23/25, 10:36 </span>

    Thanks for the report. I believe this to be “just” a missing documentation specificity.

    In fact, “findByUid” is NOT a magic method. It is specifically implemented, and thus was NOT deprecated. The changelog does not explicitly mention that, because only real “magic” methods are addressed.

    So you could continue to use findByUid if that implementation detail is important. Adding a change like you propose would possibly lead to breaking changes for others who may rely on the behavior you want (which can be achieved by findByUid (findByIdentifier actually ;)).

    So I would suggest we patch the changelog and add a note like:

    Please note that the (not-magic) method `findByUid()` did NOT get deprecated or removed, and is still valid to be used. Using this method will also by default not respect storage page settings, and fetch the object straight via its identifier.
    What do you think? Would you maybe want to contribute a changelog core patch for this? :-)
  2. Georg Ringer commented <span data-processor="relativetime" data-value="2025-04-23T13:44:04+00:00" > 04/23/25, 13:44 </span>

    however, findByUid can be also switched to findByIdentifier ^^

  3. Christian Hackl commented <span data-processor="relativetime" data-value="2025-04-23T14:53:12+00:00" > 04/23/25, 14:53 </span>

    oh ok, I wasn’t aware that this method wasn’t one of the “magic” methods, I thought all findBy* were “magic” methods, I didn’t look properly – then please excuse my mistake.
    However, yes, it would certainly be nice to have a corresponding note in the changelog :)

  4. Georg Ringer commented and changed status Needs Feedback Closed <span data-processor="relativetime" data-value="2025-04-23T18:54:33+00:00" > 04/23/25, 18:54 </span>

    closing in favor of #106603