Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[usd] Fix metadata authoring bug. #529

Closed

Conversation

superfunc
Copy link
Contributor

Description of Change(s)

Previously, authoring metadata from python, such as in CustomData, USD would allow python lists, but would not convert them to the proper VtArray type. This would cause layers to be unreadable, unserializable etc.

For example,

from pxr import Usd

s = Usd.Stage.CreateInMemory()
p = s.DefinePrim('/p')

p.SetCustomDataByKey('int_array', [1,2,3,4])
print s.ExportToString()

Produces the following broken file (notice the missing typename):

#usda 1.0
(
    doc = """Generated from Composed Stage of root layer 
"""
)

def "p" (
    customData = {
         int_array = [1, 2, 3, 4]
    }
)
{
}

Following my change, we produce a working file:

#usda 1.0
(
    doc = """Generated from Composed Stage of root layer 
"""
)

def "p" (
    customData = {
        int[] int_array = [1, 2, 3, 4]
    }
)
{
}

My change also disallows unknown list types, so bogus authoring can't get in anymore(e.g. if someone tried to author a list of Foo()s).

Fixes Issue(s)

  • None filed.

@jtran56
Copy link

jtran56 commented Jun 15, 2018

Filed as internal issue #161890.

Previously, authoring metadata from python, such as in CustomData,
USD would allow raw python lists, but would not convert them to
the proper VtArray type. This would cause layers to be unable to
export <-> import roundtrip, as well as unable to serialize to crate.
@superfunc
Copy link
Contributor Author

Rebased and clean with dev.

@superfunc
Copy link
Contributor Author

@spiffmon Sunya and I discussed this one offline; do you see anything wrong with this approach? I'm not as familiar with stuff in Vt so I wasn't sure.

@spiffmon
Copy link
Member

spiffmon commented Sep 25, 2018 via email

@superfunc
Copy link
Contributor Author

1,2: Very good points, missed that. Checking on each element seems expensive, I'll see if there is a boost python way to check if a list is homogeneous.
3: Not sure, I'll check.

@superfunc
Copy link
Contributor Author

@spiffmon Yeah, looks like the problem lives in Sdf, as well:

>>> p.SetInfoDictionaryValue('customData', 'int_array', ["foo",2,3,4])
>>> print l.ExportToString()
#sdf 1.4.32

def "p" (
    customData = {
         int_array = [foo, 2, 3, 4]
    }
)
{
}

I'll get a separate PR together that fixes that one as well (will clean this one up later this week).

@superfunc
Copy link
Contributor Author

Actually, I wonder if the problem lives lower, in VtValues casting functions that this relies on. I'll need to dig a bit more to be sure.

pixar-oss pushed a commit that referenced this pull request Nov 21, 2018
See #529

(Internal change: 1913374)
(Internal change: 1913447)
@superfunc
Copy link
Contributor Author

Looks like @gitamohr fixed this in his referenced commit, closing out.

@superfunc superfunc closed this Jan 20, 2019
AdamFelt pushed a commit to autodesk-forks/USD that referenced this pull request Apr 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants