TYPO3-Headless / headless

TYPO3 Headless JSON API providing content for PWA application (e.g. javaScript apps like nuxt-typo3)
https://t3headless.io
GNU General Public License v2.0
160 stars 61 forks source link

DatabaseQueryProcessor with returnFlattenObject=1 Does Not Return null When No Entries Are Found #797

Open KrohnMi opened 5 days ago

KrohnMi commented 5 days ago

Describe the bug When using the DatabaseQueryProcessor with the option returnFlattenObject=1, the processor returns a flatten object (e.g., an empty array) instead of null when no entries are found. This behavior is inconsistent with expectations, as returning null would make it clear that no results exist.

This issue impacts use cases where the absence of entries needs to be explicitly detected, and the current behavior introduces ambiguity.

To Reproduce Steps to reproduce the behavior:

  1. Configure a DatabaseQueryProcessor in TypoScript with the option returnFlattenObject=1.
  2. Query a database table with conditions that result in no matching entries.
  3. Observe the output.
lib.queryExample = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
lib.queryExample {
    table = your_table
    pidInList = 1
    where = some_field = 'non_existing_value'
    returnFlattenObject = 1
}

Expected behavior null is returned when no entries match the query.

Actual behavior An empty object/array is returned.

TYPO3 version and TYPO3 Headless version Typo3: 12.4.23 Headless: 4.5.