From 5a9131a1165ce59b99b62a67fedceca28d381df9 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 24 Aug 2017 14:43:27 +1200 Subject: [PATCH] FIX Do not try and access sessions when they are not ready --- src/ORM/DB.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ORM/DB.php b/src/ORM/DB.php index 48fedc98e..9f57b9eb8 100644 --- a/src/ORM/DB.php +++ b/src/ORM/DB.php @@ -233,11 +233,17 @@ class DB if (Director::is_cli()) { return false; } + // Skip if there's no request object yet if (!Injector::inst()->has(HTTPRequest::class)) { return null; } /** @var HTTPRequest $request */ $request = Injector::inst()->get(HTTPRequest::class); + // Skip if the session hasn't been started + if (!$request->getSession()->isStarted()) { + return null; + } + $name = $request->getSession()->get(self::ALT_DB_KEY); if (self::valid_alternative_database_name($name)) { return $name;