# Sdf Namespace editing : 'Object already exists'?

**URL:** <https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493>\
**Category:** USD\
**Created:** [June 2, 2025, 8:40pm UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493 "2025-06-02T20:40:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![deboisj](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@deboisj](https://forum.aousd.org/u/deboisj)\
**Post date:** [June 2, 2025, 8:40pm UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493/1 "2025-06-02T20:40:59Z")

</div>

Hello,

I am trying to perform some namespace edits using SDF - and I am hitting a strange (at least to me) issue.

Given the python code below, I am getting a “object already exists” error :

`(False, [Sdf.NamespaceEditDetail(Sdf.NamespaceEditDetail.Error,Sdf.NamespaceEdit(Sdf.Path('/root{color=blue}sphere'),Sdf.Path('/root{tint=blue}sphere'),-1),'Object already exists')]) `

I’ve succesfully used similar code to namespace edit between variants of the same set, but now to a different set… no luck. Looking at the CanApply/Process code in cpp, it seems to just be calling “layer.GetObjectAtPath()”… I am not sure how it can possibly return something valid for `/root{tint=blue}sphere'` before the edit actually happens…?

Thanks in advance!

```auto

from pxr import Usd, Sdf

stage = Usd.Stage.CreateInMemory()
root_prim = stage.DefinePrim('/root')
vset = root_prim.GetVariantSets().AddVariantSet('color')
vset.AddVariant('red')
vset.AddVariant('blue')
vset.AddVariant('green')

vset.SetVariantSelection('blue')

with vset.GetVariantEditContext():
	blue_sphere = stage.DefinePrim('/root/sphere', 'Sphere')
	blue_sphere.CreateAttribute('size', Sdf.ValueTypeNames.Double).Set(2.0)

layer = stage.GetRootLayer()

Sdf.CreatePrimInLayer(layer, '/root{tint=blue}')

namespace_edits = Sdf.BatchNamespaceEdit()
namespace_edits.Add(Sdf.Path('/root{color=blue}sphere'), Sdf.Path('/root{tint=blue}sphere'))

print(layer.CanApply(namespace_edits))

```

---

<div class="post-metadata">

**Author:** ![deboisj](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@deboisj](https://forum.aousd.org/u/deboisj)\
**Post date:** [June 2, 2025, 8:58pm UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493/2 "2025-06-02T20:58:57Z")

</div>

OK I believe there is a bug here. I can work around the issue using an intermediate variant “tmp”.

```auto
from pxr import Usd, Sdf

stage = Usd.Stage.CreateInMemory()
root_prim = stage.DefinePrim('/root')
vset = root_prim.GetVariantSets().AddVariantSet('color')
vset.AddVariant('red')
vset.AddVariant('blue')
vset.AddVariant('green')

vset.SetVariantSelection('blue')

with vset.GetVariantEditContext():
	blue_sphere = stage.DefinePrim('/root/sphere', 'Sphere')
	blue_sphere.CreateAttribute('size', Sdf.ValueTypeNames.Double).Set(2.0)

layer = stage.GetRootLayer()

Sdf.CreatePrimInLayer(layer, '/root{tint=tmp}')

namespace_edits = Sdf.BatchNamespaceEdit()
namespace_edits.Add(Sdf.Path('/root{color=blue}sphere'), Sdf.Path('/root{tint=tmp}sphere'))
layer.Apply(namespace_edits)

variant_set = layer.GetPrimAtPath('/root').variantSets['color']
variant_set.RemoveVariant(variant_set.variants['blue'])

Sdf.CreatePrimInLayer(layer, '/root{tint=blue}')

namespace_edits = Sdf.BatchNamespaceEdit()
namespace_edits.Add(Sdf.Path('/root{tint=tmp}sphere'), Sdf.Path('/root{tint=blue}sphere'))
print(layer.CanApply(namespace_edits))
layer.Apply(namespace_edits)

```

It sees that a variant named blue already exists… but it doesnt realise that it is for a different variant set - and therefor should not collide.

I will log an issue.

---

<div class="post-metadata">

**Author:** ![deboisj](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@deboisj](https://forum.aousd.org/u/deboisj)\
**Post date:** [June 2, 2025, 9:03pm UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493/3 "2025-06-02T21:03:54Z")

</div>

Logged here [Variant set namespace editing fails on erroneous "object already exists" · Issue #3658 · PixarAnimationStudios/OpenUSD · GitHub](https://github.com/PixarAnimationStudios/OpenUSD/issues/3658)

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [June 2, 2025, 11:51pm UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493/4 "2025-06-02T23:51:25Z")

</div>

On the surface it sure does sound like a bug. Thanks for filing the Issue - we’ll have a look! Also, it makes me recall that we **did** find and fix some variant-related bugs as part of the namespace editing work over the past year - I didn’t see in the Issue which version of OpenUSD you were using?

---

<div class="post-metadata">

**Author:** ![deboisj](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@deboisj](https://forum.aousd.org/u/deboisj)\
**Post date:** [June 3, 2025, 11:06am UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493/5 "2025-06-03T11:06:09Z")

</div>

Ha, indeed i have not tried the very latest release. I am on 24.11. I will try and close my issue if already fixed. Thanks.

---

<div class="post-metadata">

**Author:** ![deboisj](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@deboisj](https://forum.aousd.org/u/deboisj)\
**Post date:** [June 3, 2025, 1:12pm UTC](https://forum.aousd.org/t/sdf-namespace-editing-object-already-exists/2493/6 "2025-06-03T13:12:42Z")

</div>

Still a problem in 25.05 :

(False, [Sdf.NamespaceEditDetail(Sdf.NamespaceEditDetail.Error,Sdf.NamespaceEdit(Sdf.Path(‘/root{color=blue}sphere’),Sdf.Path(‘/root{tint=blue}sphere’),-1),‘Object already exists’)])
