-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
yaml-merge is very slow or stuck when merging Arrays or Arrays-of-Hashes into a nonexistent path #220
Comments
Wow! There are innumerable tests for the Merger class and the yaml-merge CLI tool. All of them pass every day. None of them pick up this edge-case. Thank you for discovering and reporting this! I'm in the midst of a major refactoring effort to adopt some significant changes to ruamel.yaml's internal workings. I'll try to get to a good pause in that effort to put out a hotfix for this issue, still using the older ruamel.yaml. |
I've arrived at this case as I was looking for a workaround for |
So I can be sure I understand, is this what you're trying to accomplish: lhs.yaml root:
is_a: hash rhs.yaml root:
- is_an
- array output.yaml root:
- is_an
- array |
Yes, or like this lhs.yaml root:
key: value rhs.yaml root:
key:
- element output.yaml root:
key:
- element |
There is a way, but I have to caution users against doing this without taking great care to be precise with how this technique is utilized. You are deliberately corrupting data (stomping a Hash into an Array). In most cases, this is undesirable. However, for specific, carefully curated cases, it can be exactly what you need. I'll present the Best Practice first, then the High Risk (But Simpler) method. In both, assume we are using the lhs.yaml and rhs.yaml in the quoted message above. Best PracticeUse a configuration file to precisely identify which Hash elements within LHS are allowed to be stomped. For this method, create a new INI-style configuration file, like this: stompies.yaml [rules]
/root = right Note that each Using this configuration file approach, you can add any number of rules to specifically identify which LHS nodes you know need to be specially handled without affecting any other nodes in the document. You can also setup other useful rules like AoH merge keys, and more. Command: Produces: ---
root:
key:
- element High Risk (But Simpler)You can also set a global configuration rule to just stomp every Hash in LHS with whatever is in RHS at the same path. Note that while this would achieve the immediate goal, it exposes your operation to perhaps unexpected results. Remember that a Command: Produces: ---
root:
key:
- element |
Operating System
Ubuntu 20.04.6 LTS
Version of Python and packages in use at the time of the issue.
Python 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:06:00)
[GCC 11.4.0] on linux
Version of yamlpath installed: 3.8.0
Version of ruamel.yaml installed: 0.17.21
Minimum sample of YAML (or compatible) data necessary to trigger the issue
merge_test_base.yaml
merge_test_mod.yaml
Alternatively, for array-of-hashes.
merge_test_mod.yaml
Complete steps to reproduce the issue when triggered via:
Expected Outcome
Immediate completion, with contents of merge_test_result.yaml
Actual Outcome
Script does not complete after several minutes, didn't wait more than that.
The text was updated successfully, but these errors were encountered: