Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling #21379

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

Merged
merged 1 commit into from
Jan 24, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Jan 23, 2017

Q A
Branch? 2.7
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets 77289b9#commitcomment-20572462
License MIT
Doc PR n/a

This fixes a BC break introduced in #21333. Instead of removing the automatic request attributes creation, we keep it but only for attributes that are mandatory (i.e. present in the route path).

Thanks to @iltar for the idea.

@chalasr
Copy link
Member Author

chalasr commented Jan 23, 2017

We could still deprecate this feature in 3.3 as it's inconsistent with other loaders, properly defining attributes is always better IMHO.

@linaori
Copy link
Contributor

linaori commented Jan 23, 2017

Can you add a test-case with the (Request $request = null) and a test with a controller like this (via WebTestCase) to prevent regressions?

What to do about the feature regarding defaults?

  • it should be kept as is
  • it should be removed
  • it should be added to the other loaders as well

@chalasr
Copy link
Member Author

chalasr commented Jan 23, 2017

What to do about the feature regarding defaults?

IMHO it should be removed, at least not kept as is, switching between two config formats for routing should not break an app.

Can you add a test-case with the (Request $request = null) and a test with a controller like this (via WebTestCase) to prevent regressions?

Sure!
Status: needs work

@stof
Copy link
Member

stof commented Jan 23, 2017

IMHO it should be removed, at least not kept as is, switching between two config formats for routing should not break an app.

Removing it makes sense, but it must be done using a deprecation first (so deprecated in 3.3 and removed in 4.0)

@chalasr chalasr force-pushed the routing/fix-bc-break branch 7 times, most recently from 33e78ce to de10ea6 Compare January 23, 2017 20:10
@chalasr
Copy link
Member Author

chalasr commented Jan 23, 2017

Functional test added. Hope the fix is good, it was not that easy 😄

Status: needs review

@fabpot
Copy link
Member

fabpot commented Jan 23, 2017

Not sure we should deprecate the feature, I think it's a nice one.

@chalasr
Copy link
Member Author

chalasr commented Jan 23, 2017

I can understand. I'll look at adding it to other formats on 3.3 if you agree

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class AnnotatedController extends ContainerAware
Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't need the container.

@chalasr chalasr force-pushed the routing/fix-bc-break branch from de10ea6 to e3eb006 Compare January 23, 2017 20:35
@chalasr chalasr force-pushed the routing/fix-bc-break branch from e3eb006 to 1d298f0 Compare January 23, 2017 20:38
@chalasr
Copy link
Member Author

chalasr commented Jan 24, 2017

Build failure is normal (high deps only).

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jan 24, 2017
@fabpot
Copy link
Member

fabpot commented Jan 24, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 1d298f0 into symfony:2.7 Jan 24, 2017
fabpot added a commit that referenced this pull request Jan 24, 2017
… attributes handling (chalasr)

This PR was merged into the 2.7 branch.

Discussion
----------

[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | 77289b9#commitcomment-20572462
| License       | MIT
| Doc PR        | n/a

This fixes a BC break introduced in #21333. Instead of removing the automatic request attributes creation, we keep it but only for attributes that are mandatory (i.e. present in the route path).

Thanks to @iltar for the idea.

Commits
-------

1d298f0 [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
@chalasr chalasr deleted the routing/fix-bc-break branch January 24, 2017 18:50
@fabpot
Copy link
Member

fabpot commented Feb 1, 2017

This is still a BC break as demonstrated by the tests of FrameworkExtraBundle: https://travis-ci.org/sensiolabs/SensioFrameworkExtraBundle/jobs/197153674

@chalasr Can you have a look at this?

@linaori
Copy link
Contributor

linaori commented Feb 1, 2017

    /**
     * @Route("/simple/multiple/{a}/{b}/")
     * @Template("@Foo/Simple/some.html.twig")
     */
    public function someMoreAction($a, $b, $c = 'c')
    {
    }

expectation is henk, bar, c as {c} is not provided. Result is henk, bar, . $c appears to be empty while it should get c as value.

@chalasr
Copy link
Member Author

chalasr commented Feb 1, 2017

I'll look into it.

@chalasr
Copy link
Member Author

chalasr commented Feb 1, 2017

Reproduced on our test case in 2.7 and 3.3 (master...chalasr:reproduce-sensioextra-test) all is fine for argument resolving.

The bottleneck seems to be in the Template annotation handling which relies on request attributes to resolve template vars: https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/3.0/EventListener/TemplateListener.php#L153.
Since we no longer set request attributes for arguments that are not expected in the route path (because it was buggy), the test is failing.
I think it should be solved on the SensioFrameworkExtraBundle by making it inject vars from both request attributes and method argument defaults.
Let me know what do you think, anyway I'll open a PR on SensioFrameworkExtraBundle later today so you can judge.

@chalasr
Copy link
Member Author

chalasr commented Feb 1, 2017

fabpot added a commit to sensiolabs/SensioFrameworkExtraBundle that referenced this pull request Feb 1, 2017
This PR was merged into the 3.0 branch.

Discussion
----------

Fix default vars resolution for Template annotation

Fixes broken `@Template` default vars resolution which was relying on a buggy behavior fixed symfony/symfony#21379 (the annotation class loader no longer sets request attributes for any argument that has a default value, but only for ones which may be expected in the route path).

Commits
-------

9ddf58a Fix default vars resolution for Template annotation
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.