-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Error when using the same route name twice in XML or YAML file #14512
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
Comments
@xabbuh wrote: Will there be a warning now? I think it would be good to add this warning if it not exists. |
Disallowing to overwrite a route is a major BC and also problems for some that use this feature. |
That's really a limitation of YAML, so there is nothing we can do as mentioned by @inso |
I think no one should rely on this behaviour. I can't think of any relevant use case where having multiple routes with the same name is valid. If you absolutely need to have something like that, then your design is probably wrong and it needs to be refactored. In Come on guys, this is a good concept:
|
I'm in favor of improving this. The YAML parser does not give a warning, when it can Developer experience is very important. And i think it does not even break the YAML spec, but infact enhance it ! Implementation wise it should be easy to do something about this, |
Adding a warning would actually degrade the experience for people who uses this documented feature of YAML. It's not "bad" to override a key in YAML. |
Is one file one YAML node? |
@Tobion This sounds like a bug if it occurs in a single file and should output a WARNING or be changed (let's say use the last?). |
@Tobion why does it make sense when combining multiple YAML files ? How can you know which file overwrites which ? Are the files containing the routes loaded in a predictable order in the case of multiple bundles ? |
@SoboLAN yes the order you import them. |
Here is a place where this is really important: So the proper solution would be to allow multiple routes with the same name and have a clear policy of which one wins, irrespective of the parser / loader used. |
@thms are you sure this does not work ? redefining routes in different files should be working AFAICT. In any case, overwriting stuff from a third-party bundle is off-topic here. this issue is about route names in a single file. |
If I may give my input: It is really a no-go to silently ignore declarations (ie. user input). Also, the spec clearly states that duplicate keys are supposed to be considered an error and, at least in 1.1 spec, that an according warning should be issued. This is currently not happening as of #10902 and is a source of painfully hard to debug errors. And yes, that has basically already been rejected with #11538, but I dare to oppose the "overhead for too little gain" resolution. Filling an internal array of spec-violations and making it accessable through the parser class is really easy opposed to the possible problems that may result from silent ignoring such. It should at least be the decision of the application if it can really ignore such illformatting or has to inform the user/developer. |
I second what @albe wrote. And dare to suspect most applications reading YAML will cache the result in a production context - so a little overhead would not hurt. |
For what is worth, according to the Yaml 1.2 Spec (which is the one used by Symfony) keys must be unique:
Source: http://www.yaml.org/spec/1.2/spec.html - Section 1.3. Relation to JSON |
Could we close this issue as fixed now that Symfony has deprecated "silently ignoring duplicate keys" and this will throw a |
@javiereguiluz will that also include naming conflicts between imported routes? That's a far more frequent source for hard to find bugs in my experience. |
@curry684 being able to override a route which is already defined is considered as a feature, so we cannot forbid it |
@stof I'm aware that it wasn't "fixed" before for BC reasons. It's however a highly frustrating experience for developers to accidentally overwrite a route name in a huge project with several local bundles and partial routing files and then subtly break existing functionality. Hence my question whether, as 4.0 also fixes the broken behavior inside YAML files, that wouldn't be a good opportunity to also fix the cross-file issue causing far more obscure bugs. |
I suppose you already had this before as well, copying a route and forgetting to rename it. The old route gets overwritten and you might not even notice it until its too late.
How about throwing an Exception when the same route name is defined twice in the same YAML or XML file to increase developer experience?
The text was updated successfully, but these errors were encountered: