silverstripe / cwp-core

CWP basic compatibility module
BSD 3-Clause "New" or "Revised" License
3 stars 12 forks source link

Uncaught Exception BadMethodCallException: "No session available for this HTTPRequest" #21

Closed phptek closed 6 years ago

phptek commented 6 years ago

Using dev-master (as at d980d7f049b9b8) in SilverStripe test mode (deployed to SilverStripe Platform UAT) when attempting to login to /admin the following exception is thrown:

Uncaught Exception BadMethodCallException: "No session available for this HTTPRequest"
at /var/www/mysite/releases/86b5b06b2217d65ec559d90e8e1280e2b2b86039/vendor/silverstripe/framework/src/Control/HTTPRequest.php
line 891

This results in an inability to even see the admin login screen, with a 500 error displaying instead.

I traced this back to Extension/CwpControllerExtension.php on line 124 where the call to getSession() in $this->owner->getRequest()->getSession()->get('AutoLoginHash') fails.

To "prove" this is the rogue logic, I removed this else if condition, redeployed and I could once again see the admin screen.

The "owner" is the current Controller which obviously (should) have a valid HTTPRequest object, but I haven't dug any deeper. Over to you @robbieaverill !?

robbieaverill commented 6 years ago

Reproduced, thanks - environments other then dev

robbieaverill commented 6 years ago

Fix at #22

dhensby commented 6 years ago

I believe this will have been fixed by https://github.com/silverstripe/silverstripe-framework/pull/7756

robbieaverill commented 6 years ago

Retesting this now

robbieaverill commented 6 years ago

Tested on 4.1.x-dev (merged up, contains https://github.com/silverstripe/silverstripe-framework/commit/a8c156a) and it's still a problem

tractorcow commented 6 years ago

Right, we have many levels of nested controllers sometimes; Hence the need for the single unified source of truth.

Makreig commented 6 years ago

I am still experiencing this on 4.2.1. I am requesting the session in onAfterInit in a Controller extension.

robbieaverill commented 6 years ago

@Makreig yeah the second patch for this in core hasn't been released yet: https://github.com/silverstripe/silverstripe-framework/pull/8324