Skip to content

[HttpFoundation] Deprecate Request::getSession() when Request::hasSession() is false #9625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

[HttpFoundation] Deprecate Request::getSession() when Request::hasSession() is false #9625

wants to merge 3 commits into from

Conversation

snoek09
Copy link

@snoek09 snoek09 commented Apr 20, 2018

This fixes #9457.

@@ -444,7 +444,9 @@ remove this variable, it's better to use the
// ...
use Symfony\Component\Security\Http\Util\TargetPathTrait;

$targetPath = $this->getTargetPath($request->getSession(), $providerKey);
$session = $request->hasSession() ? $request->getSession() : throw_no_session_exception();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not convinced we should throw an exception here. Not having a session looks valid to me and we should then just use the empty value as the target path IMO.

@@ -235,6 +235,13 @@ the
method tells you if the request contains a session which was started in one of
the previous requests.

.. versionadded:: 4.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the blank line must be removed

Using :method:`Symfony\\Component\\HttpFoundation\\Request::getSession()` when no session
has been set, was deprecated in Symfony 4.1. It will throw an exception in
Symfony 5.0 when session is null.
Use :method:`Symfony\\Component\\HttpFoundation\\Request::hasSession()` instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would this reword to say something like "Check for an existing session first by calling Request::hasSession()."

@xabbuh xabbuh added this to the 4.1 milestone Apr 20, 2018
@xabbuh
Copy link
Member

xabbuh commented Apr 20, 2018

@snoek09 I would still update form_login.rst to check if the session actually exists.

never mind, that part would have failed previously too if there is no session

@@ -235,6 +235,12 @@ the
method tells you if the request contains a session which was started in one of
the previous requests.

.. versionadded:: 4.1
Using :method:`Symfony\\Component\\HttpFoundation\\Request::getSession()`
when no session has been set, was deprecated in Symfony 4.1. It will throw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comma could be removed

.. versionadded:: 4.1
Using :method:`Symfony\\Component\\HttpFoundation\\Request::getSession()`
when no session has been set, was deprecated in Symfony 4.1. It will throw
an exception in Symfony 5.0 when session is null. Check for an existing session
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] when the session [...]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and "null" should be enclosed by double backticks

@javiereguiluz
Copy link
Member

A nice deprecation message! Thanks for contributing it.

@snoek09 snoek09 deleted the deprecate-get-sesion-when-has-session-is-false branch April 23, 2018 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpFoundation] deprecate call to Request::getSession() when Request::hasSession() returns false
4 participants