APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
492 stars 344 forks source link

Is it possible that $row->getEntity() returns null #1025

Closed lmeyer closed 4 years ago

lmeyer commented 5 years ago

Hello,

Sentry reported an error that seems weird.

Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getBottle() on null in xxxx/AppBundle/Grid/TransactionGrid.php:200

Involved code is

$column = new TextColumn([
    'id'                 => 'format',
    'field'              => 'bottle.format.name',
    'title'              => 'Format',
    'source'             => true,
    'sortable'           => true,
    'operatorsVisible'   => false,
]);

$column->manipulateRenderCell(function($value, $row) {
    return $row->getEntity()->getBottle()->getFormat()->getName();
});

$this->grid->addColumn($column, 14);

So getEntity returned null this time.

The website is heavily used, but the problem appeared only one time so it's not a big deal. But I prefer to ask.

Regards,

petrofcikmatus commented 5 years ago

Hi @lmeyer,

yes, according to code in APY\DataGridBundle\Grid\Row, method Row::getEntity() can return null or object.


<?php
namespace APY\DataGridBundle\Grid;

use Doctrine\ORM\EntityRepository;

class Row
{
    //...
    /**
     * @return null|object
     */
    public function getEntity()
    {
        $primaryKeyValue = current($this->getPrimaryKeyValue());

        return $this->repository->find($primaryKeyValue);
    }
    //...
}
npotier commented 4 years ago

Hello, I'm closing this issue since the behaviour is normal and not a bug