cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x]: Live preview not working with disabled site

Open samuel-clara opened this issue 9 months ago • 3 comments

What happened?

Description

When a site is globally disabled in the settings → sites

the live preview function in the CP produces an error when previewing an entry from the disabled site with a twig template that uses

.language(craft.app.language)

full query is {% set entryQuery = craft.entries().site('*').language(craft.app.language).section('section') %}

The error is "Invalid Argument Invalid site: 5"

Steps to reproduce

  1. disable a site
  2. live preview an entry from this site that uses a entry query with .language(craft.app.language)

Expected behavior

  1. previewing an entry of an unpublished site should be possible

Actual behavior

  1. not possible to see the preview

Craft CMS version

5.7.6

PHP version

8.4

Operating system and version

No response

Database type and version

Mysql 8.0

Image driver and version

No response

Installed plugins and versions

samuel-clara avatar May 22 '25 13:05 samuel-clara

I’m not able to reproduce that locally. Please search for that error in your logs (storage/logs) and post the stack trace that follows it.

brandonkelly avatar May 22 '25 22:05 brandonkelly

FWIW, this sounds a lot like what I ran into with #15767.

mmikkel avatar May 22 '25 22:05 mmikkel

2025-05-22 15:17:08 [web.ERROR] [yii\base\InvalidArgumentException] yii\base\InvalidArgumentException: Invalid site: 5 in /var/www/html/craft/vendor/craftcms/cms/src/services/Sites.php:504
Stack trace:
#0 /var/www/html/craft/vendor/putyourlightson/craft-blitz/src/controllers/IncludeController.php(60): craft\services\Sites→setCurrentSite()
#1 /var/www/html/craft/vendor/putyourlightson/craft-blitz/src/controllers/IncludeController.php(31): putyourlightson\blitz\controllers\IncludeController→getRenderedTemplate()
#2 [internal function]: putyourlightson\blitz\controllers\IncludeController→actionCached()
#3 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#4 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction→runWithParams()
#5 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller→runAction()
#6 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(361): yii\base\Module→runAction()
#7 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(660): craft\web\Application→runAction()
#8 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(323): craft\web\Application→_processActionRequest()
#9 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application→handleRequest()
#10 /var/www/html/public_html/index.php(12): yii\base\Application→run()
#11 {main} {"memory":3073816,"exception":"[object] (yii\\base\\InvalidArgumentException(code: 0): Invalid site: 5 at /var/www/html/craft/vendor/craftcms/cms/src/services/Sites.php:504)"} 

I also checked this with Ben Croker (issue) from Blitz but as he suggested this seems more likely to be a craft cms related problem. It happens also without using Blitz.

samuel-clara avatar May 23 '25 07:05 samuel-clara