Returning null item for no reason

Try this one…

import wixData from 'wix-data';
const myDatabase = 'MyAll2';


$w.onReady(async()=> {console.log("Page ready...");
    
    $w('#gender').onChange(async() => {
        console.log("Gender-Switch changed!");
        if ($w('#genderDecorBackButton').checked) {$w('#genderDecorBackButton').checked===false}
        else {$w('#genderDecorBackButton').checked===true;}
    
        let dataQuery = wixData.query(myDatabase);

        if ($w('#gender').checked) {console.log("Gender = Women");
            dataQuery = dataQuery.hasSome('gender', 'Women');}
        else {console.log("Gender = Men");
            dataQuery = dataQuery.hasSome('gender', 'Men'); 
        }
   
        dataQuery.find()
        .then((res)=>{console.log("Results: ", res.items);
            let items = res.items;
            $w('#productList1').data =items;
        });        
    });


    $w('#productList1').onItemReady(async ($item, itemData) => {
        let productID = itemData.product._id;
        console.log("Product-ID: ", productID);
        let price = itemData.product.price;
        console.log("Price: ", price);
        let discountedPrice = itemData.product.discountedPrice;
        console.log("Discounted-Price: ", discountedPrice);

        if (discountedPrice===itemData.product.price) {
            $item('#discountBox2, #discount2').hide();}
        else {$item('#discount2').text = String(
            100-Math.round(100*discountedPrice/price)) + "% off";
            //$item('#discountBox2, #discount2').show();
        }

        //const actualProduct = await 
        
        wixData.query(myDatabase)
        .include('brand')
        .eq('product', productID)
        .find()
        .then((res) => {console.log("Results-2: ", res);
            let items = res.items;
            if (items.length > 0) {
                let actualProduct = items[0];
                console.log("Actual-Product: ", actualProduct);
                let logoBack = actualProduct.brand.logoblack;
                console.log("Back-Logo: ", logoBack);

                if (actualProduct && actualProduct.brand) {
                    if (logoBack.startsWith('http://') || logoBack.startsWith('https://') || logoBack.startsWith('wix:image://')) {
                        $item('#logo1').src = logoBack;
                    }
                } 
                else {console.error("Error: Cannot read 'logoblack' property from undefined or null object.");}
            
                $item('#colors1').text = itemData.color.length + " colors";
                if (itemData.ecoFriendly) $item('#ecoFriendlySign3').expand();
                if (itemData.sustainable) $item('#sustainableSign3').expand();
            }           
        });       
    });
});
  1. Check all the console-logs.

  2. Another thing…reading once again your description…found…

The problem: If I switch the gender, and switch it back in the initial position for example ( From Women to Men, and back to the Women) The actualProduct which I use to take the brand image is returned null. The actualProduct is giving me the product and using .include(brand) is letting me navigate through the brand item from an another dataset, from where I get the black version of the logo (“logoblack”). This is irelevant, why is this happening. Nothing changes, why is returning a null object.

WHAT ??? ----> you are using a —> DATASET ?
Where is your dataset inside your code?
Is your dataset already —> READY <— when you start to work with it?

Or did you want to say —> Database intead of DATASET ???

If you are using a DATASET → this would change ----> EVERYTHING !!!

And next time try not to write a whole roman of description.
It would be ok, if you would provide just the main important things someone has to know, like…

  1. I am using a dataset…(dynamic/non-dynamic) with the ID…
  2. I have a database with the ID …
  3. My dataset is connected to the DB with the ID …
  4. I am working on a —> Product-Page
  5. I have a repeater on that product page… with the ID…
  6. and so on…
  7. here my working/not working code…

My question…

Done…

If that still not work, take a look onto CONSOLE-LOGS.
Make a screen of the LOGS → and show a PICTURE of the log here (+describe the issue).