Skip to content

Fix missing default class name when attaching a spec without prefix or suffix#3333

Open
discobot wants to merge 1 commit into
google-deepmind:mainfrom
discobot:fix/2707-attach-default-main-clobber
Open

Fix missing default class name when attaching a spec without prefix or suffix#3333
discobot wants to merge 1 commit into
google-deepmind:mainfrom
discobot:fix/2707-attach-default-main-clobber

Conversation

@discobot

Copy link
Copy Markdown

Fixes #2707.

The attach paths copy the child's root default tree and only apply
mjCDef::NameSpace, which prepends the prefix/suffix to each name. With an
empty prefix and suffix the copy keeps the reserved name main, and
mjCModel::operator+=(mjCDef&) inserted it without a collision check, silently
overwriting def_map["main"]. Since the XML writer omits the class attribute
for any default named main and resolves every element's class through
def_map, this both emits the nameless nested <default/> and corrupts how the
parent's own elements are serialized.

This change renames the incoming default tree's root to a unique name
(main_1, ...) in mjCModel::operator+=(mjCDef&) before insertion, mirroring
the disambiguation that non-empty prefixes already provide. It also covers the
more general collision — e.g. parent and child both defining a class with the
same name, or attaching the same spec twice with identical prefixes — which
previously serialized as duplicate class names that fail to reload with
"repeated default class name".

Added a regression test that attaches a child spec with defaults using empty
prefix/suffix and checks that the parent's global default is not clobbered, the
saved XML loads back, and the reloaded model is identical. Before the fix it
fails with XML Error: empty class name; with the fix the user and XML test
suites pass.

@google-cla

google-cla Bot commented Jun 13, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

…r suffix

When a spec is attached with an empty prefix and suffix, the copy of the
child's global default keeps the name 'main', silently overwrites the
parent's entry in def_map and is serialized as a nameless <default/>
element that cannot be parsed back. Make the name of an attached default
tree unique before inserting it into the model, matching the behavior
already produced by non-empty prefixes. Add a regression test attaching a
spec without prefix or suffix and verifying that the saved XML round-trips.

Fixes google-deepmind#2707.
@discobot discobot force-pushed the fix/2707-attach-default-main-clobber branch from 1123939 to f1d3512 Compare June 13, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default class name missing when the spec attached to a parent without a suffix and prefix

1 participant