Magento – getTable() does not work in core code on core table

ce-1.8.0.0

In Mage_Sales_Model_Resource_Report_Bestsellers_Collection::_initSelect() on Line 138

$mainTable = $this->getTable('sales/bestsellers_aggregated_yearly');

Magento throws an error: Can't retrieve entity config: sales/bestsellers_aggregated_yearly but table sales_bestsellers_aggregated_yearly does exist.

Why does Magento not find this table?

I did a Magento update from ce-1.4.0.1 that might have messed up something…

Update

getTable() is calling Mage_Core_Model_Resource::getTableName() and this looks like this:

    $parts = explode('/', $modelEntity);
    if (isset($parts[1])) {
        list($model, $entity) = $parts;
        $entityConfig = false;
        if (!empty(Mage::getConfig()->getNode()->global->models->{$model}->resourceModel)) {
            $resourceModel = (string)Mage::getConfig()->getNode()->global->models->{$model}->resourceModel;
            $entityConfig  = $this->getEntity($resourceModel, $entity);
        }

        if ($entityConfig && !empty($entityConfig->table)) {
            $tableName = (string)$entityConfig->table;
        } else {
            Mage::throwException(Mage::helper('core')->__('Can\'t retrieve entity config: %s', $modelEntity));
        }

In app/code/core/Mage/Sales/etc/config.xml the correct table is defined as sales_bestsellers_aggregated_yearly with the config path:

/config/global/models/sales_resource/entities/bestsellers_aggregated_yearly

To find modules messing with this config i did:

grep -R "bestsellers_aggregated_yearly" app/

And found only core files:

app/code/core/Mage/Sales/Model/Resource/Report/Bestsellers/Collection.php
app/code/core/Mage/Sales/sql/sales_setup/*
app/code/core/Mage/Sales/etc/config.xml

Best Answer

Problem was a module's etc/config.xml which was overwriting resourceModel of <sales>:

    <models>
        <sales>
            <class>Mage_Sales_Model</class>
            <resourceModel>sales_mysql4</resourceModel>
        </sales>
         ...

It was a copy of the old Sales config that did not include bestsellers_aggregated_yearly nor any other new stuff. I removed this bad config completely because it contained no change compared to the sales config in the old Magento core.