Skip to content
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

Fix loading nested include with custom attributes #789

Merged
merged 2 commits into from
Dec 17, 2021

Conversation

jennuine
Copy link
Collaborator

🦟 Bug fix

Closes #502

Summary

When working on tests for #502 , I found a bug with nested includes where the included file contained custom attributes. In the parser's addNestedModel call, after the string replacement for flattening, the _includeSDF element was cleared but not it's attributes. This resulted in the custom attribute being added twice and the duplicate attribute would be left with an empty value. This PR fixes the issue by clearing the attributes before calling readString and adds tests to ensure custom elements/attributes are preserved when loading a sdformat file and reloading the string output.

Before PR
Check out this PR and comment out _includeSDF->RemoveAllAttributes() from:
https://github.com/ignitionrobotics/sdformat/blob/1c6c0a55d07cc75057f8cc44c5a25b85f155ee8e/src/parser.cc#L1375-L1377

Then run:

./path/to/build/test/integration/INTEGRATION_sdf_custom --gtest_filter=SDFParser.ReloadNestedIncludedCustomElements

The error is:

Required attribute[xmlns:mysim] in element[sdf] is not specified in SDF.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@github-actions github-actions bot added Gazebo 1️1️ Dependency of Gazebo classic version 11 🏰 citadel Ignition Citadel labels Dec 16, 2021
@jennuine jennuine changed the title nested include w/ custom elem bug fix Fix loading nested include with custom attributes Dec 16, 2021
@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2021

Codecov Report

Merging #789 (c54dccb) into sdf9 (3266e33) will increase coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             sdf9     #789      +/-   ##
==========================================
+ Coverage   87.46%   87.56%   +0.10%     
==========================================
  Files          63       63              
  Lines        9893     9894       +1     
==========================================
+ Hits         8653     8664      +11     
+ Misses       1240     1230      -10     
Impacted Files Coverage Δ
src/parser.cc 79.05% <100.00%> (+1.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3266e33...c54dccb. Read the comment docs.

world2->Element()->FindElement("mysim:description");
ASSERT_NE(nullptr, customDesc1);
ASSERT_NE(nullptr, customDesc2);
EXPECT_EQ(customDesc1->ToString(""), customDesc2->ToString(""));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we compare the result of customDesc2->ToString with the expected string literal instead of trusting customDesc1->ToString is working properly? Here and below. Not to make to verbose, I would only do it on the comparisons that involve custom elements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-01-10/1228/1

@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-03-25-fortress-edifice-citadel/1343/1

@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-04-13-fortress-edifice/1367/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel Gazebo 1️1️ Dependency of Gazebo classic version 11
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants