terminal42 / contao-node

Manage content centrally as nodes and reuse them everywhere.
MIT License
29 stars 8 forks source link

Unknown column 'tags' in 'field list' #11

Closed bytehead closed 5 years ago

bytehead commented 5 years ago

Right after a fresh install (1.0.1) accessing the backend module:

An exception occurred while executing 'SELECT DISTINCT `tags` FROM tl_node':
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags' in 'field list'

Stacktrace:

Doctrine\DBAL\Exception\InvalidFieldNameException:
An exception occurred while executing 'SELECT DISTINCT `tags` FROM tl_node':

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags' in 'field list'

  at vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:80
  at Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception occurred while executing \'SELECT DISTINCT `tags` FROM tl_node\':SQLSTATE[42S22]: Column not found: 1054 Unknown column \'tags\' in \'field list\'', object(PDOException))
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:184)
  at Doctrine\DBAL\DBALException::wrapException(object(Driver), object(PDOException), 'An exception occurred while executing \'SELECT DISTINCT `tags` FROM tl_node\':SQLSTATE[42S22]: Column not found: 1054 Unknown column \'tags\' in \'field list\'')
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:158)
  at Doctrine\DBAL\DBALException::driverExceptionDuringQuery(object(Driver), object(PDOException), 'SELECT DISTINCT `tags` FROM tl_node', array())
     (vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:943)
  at Doctrine\DBAL\Connection->executeQuery('SELECT DISTINCT `tags` FROM tl_node')
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Database/Statement.php:277)
  at Contao\Database\Statement->query()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Database/Statement.php:251)
  at Contao\Database\Statement->execute(array())
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:5633)
  at Contao\DC_Table->filterMenu(1)
     (vendor/contao/core-bundle/src/Resources/contao/classes/DataContainer.php:1154)
  at Contao\DataContainer->panel()
     (vendor/contao/core-bundle/src/Resources/contao/drivers/DC_Table.php:349)
  at Contao\DC_Table->showAll()
     (vendor/contao/core-bundle/src/Resources/contao/classes/Backend.php:618)
  at Contao\Backend->getBackendModule('nodes', null)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/BackendMain.php:169)
  at Contao\BackendMain->run()
     (vendor/contao/core-bundle/src/Controller/BackendController.php:48)
  at Contao\CoreBundle\Controller\BackendController->mainAction()
     (vendor/symfony/http-kernel/HttpKernel.php:150)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:67)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request), 1, true)
     (src/HttpKernel/AppCache.php:50)
  at App\HttpKernel\AppCache->handle(object(Request))
     (public/index.php:33)
fritzmg commented 5 years ago

Are you sure you have executed the database updates in the Contao Install Tool? (You have to update two times.)

bytehead commented 5 years ago

Yes. Seems that the SQL statement is missing: https://github.com/terminal42/contao-node/blob/c1c54d56d21e73ebbd03f12fff80ac41118b4cd6/src/Resources/contao/dca/tl_node.php#L156-L162

fritzmg commented 5 years ago

That's normal, as far as I understand it. Tags aren't saved directly in that table. It's managed by the tags-bundle.

bytehead commented 5 years ago

But Contao tries to select this column: 'SELECT DISTINCT tags FROM tl_node'.

fritzmg commented 5 years ago

Which Contao version?

bytehead commented 5 years ago

4.7.7

fritzmg commented 5 years ago

It's odd. We are using this extension in Contao 4.7 as well without experiencing this issue.

bytehead commented 5 years ago

I think I got the issue. Let me check quick.

qzminski commented 5 years ago

Exactly like @fritzmg pointed out the tags are managed by codefog/tags-bundle and thus the bug is not strictly related to this extension. However it still seem a bit weird to me because for tag management we do use a relational table and Contao should never try to fetch the tags column directly. Let me know what you'll find out.

richardhj commented 5 years ago

AFAIK this query comes from the filter panel. But don’t know how this works together.

qzminski commented 5 years ago

@richardhj fields that use Haste-ManyToMany relation also use a filter callback to replace those default Contao filters with custom ones, so this shouldn't be a problem here… unless there is a bug :wink:

bytehead commented 5 years ago

I'm much further now:

An exception occurred while executing 'SELECT cfg_tag_id FROM tl_cfg_tag_node':

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sc_website.tl_cfg_tag_node' doesn't exist

I have to explain here that we run our Contao database updates on CLI (not via install tool). Problem is, that commands runnning on CLI don't have a TL_MODE, (it's actual value is null). Finally this hook gets missed by the schema tool on CLI:

https://github.com/codefog/contao-haste/blob/74780c97966f3f85ad120fa32ffef25845e7cec2/config/config.php#L39-L41

bytehead commented 5 years ago

Any ideas how to solve this? 😀

qzminski commented 5 years ago

If we change this one to

if (!defined('TL_MODE') || TL_MODE == 'BE') {
    $GLOBALS['TL_HOOKS']['sqlGetFromFile'][] = ['Haste\Model\Relations', 'addRelationTables'];
}

it should then work, right?

bytehead commented 5 years ago

Hm, it is actually defined (has value null).

if (!TL_MODE || TL_MODE === 'BE') { ... }

would work.

fritzmg commented 5 years ago

Or just TL_MODE !== 'FE' … ?

qzminski commented 5 years ago

Right, it is defined… so let's go with @fritzmg proposal which was my second though. I will release the Haste hotfix in a few minutes.

bytehead commented 5 years ago

Nice, thanks for hotfixing @qzminski! 🍻