10000 [FrameworkBundle] Remove redundant `name` attribute from `default_context` by HypeMC · Pull Request #53657 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Remove redundant name attribute from default_context #53657

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 29, 2024

Conversation

HypeMC
Copy link
Contributor
@HypeMC HypeMC commented Jan 28, 2024
Q A
Branch? 7.1
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

This attribute name doesn't exist. It's not defined in the XML schema, and it doesn't do anything. default_context is just a simple array that's passed to the serializer.

@smnandre
Copy link
Member

In YAML, the 'name' argument of useAttributeAsKey() has a special meaning and refers to the key of the map (sf_connection and default in this example). If a child node was defined for the connections node with the key name, then that key of the map would be lost.

See https://symfony.com/doc/current/components/config/definition.html#array-node-options

@HypeMC
Copy link
Contributor Author
HypeMC commented Jan 28, 2024

@smnandre Well yes, it does make sense in the example, and in some other cases such as scoped_clients, but it still doesn't make sense for the default_context. You cannot do, for example, something like:

framework:
    serializer:
        default_context:
            -
                name: one
                enable_max_depth: true
                yaml_indentation: 2
            -
                name: two
                enable_max_depth: true
                yaml_indentation: 2

@smnandre
Copy link
Member

As i read it you can do the following:

framework:
  serializer:
    default_context:
      foo: bar
      blop: blip
      name: name

@HypeMC
Copy link
Contributor Author
HypeMC commented Jan 29, 2024

@smnandre You can still do that even with this change.

@smnandre
Copy link
Member

As of writing this, there is an inconsistency: if only one file provides the configuration in question, the keys (i.e. sf_connection and default) are not lost. But if more than one file provides the configuration, the keys are lost as described above.

@HypeMC
Copy link
Contributor Author
HypeMC commented Jan 29, 2024

@smnandre Sorry, I'm not sure what the point of your last response was.

@nicolas-grekas
Copy link
Member

Let's change this on 7.1, this is not a bugfix to me.

@HypeMC HypeMC force-pushed the serializer-remove-redundant-config branch from fa46205 to af31d97 Compare January 29, 2024 09:11
@HypeMC HypeMC changed the base branch from 5.4 to 7.1 January 29, 2024 09:11
@HypeMC HypeMC force-pushed the serializer-remove-redundant-config branch from af31d97 to 485b756 Compare January 29, 2024 09:12
@HypeMC
Copy link
Contributor Author
HypeMC commented Jan 29, 2024

@nicolas-grekas Done

@chalasr
Copy link
Member
chalasr commented Jan 29, 2024

Thank you @HypeMC.

@chalasr chalasr merged commit e00c12e into symfony:7.1 Jan 29, 2024
@smnandre
Copy link
Member

@smnandre Sorry, I'm not sure what the point of your last response was.

@HypeMC I've spend a looong time trying to reproduce a case where those keys were lost, justifiying this call... and failed massively. Will bring concrete evidence (if it exists) before commenting next time.. Sorry for that, lesson learned.

@HypeMC HypeMC deleted the serializer-remove-redundant-config branch January 30, 2024 02:22
@HypeMC
Copy link
Contributor Author
HypeMC commented Jan 30, 2024

@smnandre No worries, better safe than sorry, thanks for investigating 😄

nicolas-grekas added a commit that referenced this pull request Aug 12, 2024
…m `default_context` (HypeMC)

This PR was merged into the 7.1 branch.

Discussion
----------

[FrameworkBundle] Re-remove redundant name attribute from `default_context`

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

This was originally removed in #53657 but was later reintroduced in v7.1.2, likely by accident, in the following merge commit: 67ac926.

Commits
-------

83fe767 [FrameworkBundle] Re-remove redundant name attribute from `default_context`
@wouterj
Copy link
Member
wouterj commented Nov 23, 2024

Let's change this on 7.1, this is not a bugfix to me.

A test on documentation examples revealed that this does create a weird situation when using the config builders.

The useAttributeAsKey signals the config builders that we expect a mapping with a key. Which creates a method with 2 arguments rather than 1.

E.g. the following snippet does not work on 6.4:

return static function (FrameworkConfig $framework): void {
    $framework->serializer()
        ->defaultContext([
            'allow_extra_attributes' => false,
        ])
    ;
};

And a user has to do something like:

return static function (FrameworkConfig $framework): void {
    $framework->serializer()
        ->defaultContext('can be anything as this is not used', [
            'allow_extra_attributes' => false,
        ])
    ;
};

I think we can consider this a bugfix for 6.4, what do you think?

fabpot added a commit that referenced this pull request Mar 17, 2025
…default_context` (HypeMC)

This PR was merged into the 6.4 branch.

Discussion
----------

[FrameworkBundle] Remove redundant `name` attribute from `default_context`

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes?
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

This was initially merged into v7.1 in #53657. However, after seeing `@wouterj`'s [comment](#53657 (comment)) (which I missed earlier), I opened this PR to see if we might want to reconsider this as a bug after all.

Commits
-------

f71a850 [FrameworkBundle] Remove redundant `name` attribute from `default_context`
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
0