Jump to content

Recommended Posts

Hi

I am struggling to work out how to create a new AssetVersion in the new API.

I think I have to do the following:

Create an Asset -- parented to the shot

Create an AssetVersion -- linking to the task and asset

Create the Component.

Unfortunately I'm getting an error, it seems to want a context_id on the Asset, but I don't know what to give it? I have the following code:

location = session.query('Location where name is "ftrack.unmanaged"').first()
task = session.query('Task where id is "d4564359-2944-49d4-93fa-b11909f19ff5"').first()
shot = session.query('Shot where id is "bf127242-da0b-40aa-ac19-ca793f7590e0"').first()

data = {
    'parent': shot,
    'name':"aAsset",
    'type':'scene'
}
asset = session.create("Asset", {})


data = {
    "task": task,
    "asset": asset,
    "name": "Philip Test",
    "version": 99,
}
version = session.create("AssetVersion", data)

component = version.create_component(
    path=r"P:\a_project\series_01\sequences\025\sq025_sh040\2d\publish\v009\040_Compositing.nk",
    data={
        'name': 'nuke_script'
    },
    location=location
)

session.commit()

And I get the following error:

 

Traceback (most recent call last):
  File "C:/Users/Philips/Documents/source_code/test_project/ftrack/create_version.py", line 51, in <module>
    location=location
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\entity\asset_version.py", line 47, in create_component
    return self.session.create_component(path, data=data, location=location)
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\session.py", line 1816, in create_component
    'FileComponent', path, data, location
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\session.py", line 1887, in _create_component
    location.add_component(component, origin_location, recursive=False)
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\entity\location.py", line 77, in add_component
    [component], sources=source, recursive=recursive
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\entity\location.py", line 249, in add_components
    transferred=transferred
ftrack_api.exception.LocationError: Failed to register components with location <UnmanagedLocation("ftrack.unmanaged", cb268ecc-8809-11e3-a7e2-20c9d081909b)> due to error:
    Server reported error: OperationalError((OperationalError) (1048, "Column 'context_id' cannot be null") 'INSERT INTO asset (id, name, context_id, taskid, type_id) VALUES (%s, %s, %s, %s, %s)' (u'6220bf4b-3d0f-45cf-aa6c-45106fd49396', None, None, None, None))
    Transferred component data that may require cleanup: [(<dynamic ftrack FileComponent object 54489720>, 'P:\\a_project\\series_01\\sequences\\025\\sq025_sh040\\2d\\publish\\v009\\040_Compositing.nk')]

 

Link to post
Share on other sites

OK my Code had a stupid mistake in it. Realised I wasn't actually passing the data to the creation of the asset, and that the context id will likely become the id of the parent.

location = session.query('Location where name is "ftrack.unmanaged"').first()
task = session.query('Task where id is "d4564359-2944-49d4-93fa-b11909f19ff5"').first()
shot = session.query('Shot where id is "bf127242-da0b-40aa-ac19-ca793f7590e0"').first()

data = {
    'parent': shot,
    'name':"aAsset",
    'type':'scene'
}
asset = session.create("Asset", data)

data = {
    "task": task,
    "asset": asset,
    "name": "Philip Test",
    "version": 99,
}
version = session.create("AssetVersion", data)

component = version.create_component(
    path=r"P:\a_project\series_01\sequences\025\sq025_sh040\2d\publish\v009\040_Compositing.nk",
    data={
        'name': 'nuke_script'
    },
    location=location
)
session.commit()

 

now get the error

No handlers could be found for logger "ftrack_api.session.Session"
Traceback (most recent call last):
  File "C:/Users/Philips/Documents/source_code/test_project/ftrack/create_version.py", line 51, in <module>
    location=location
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\entity\asset_version.py", line 47, in create_component
    return self.session.create_component(path, data=data, location=location)
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\session.py", line 1816, in create_component
    'FileComponent', path, data, location
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\session.py", line 1887, in _create_component
    location.add_component(component, origin_location, recursive=False)
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\entity\location.py", line 77, in add_component
    [component], sources=source, recursive=recursive
  File "L:\script_library\pipeline\libs\3rd_party\production\ftrack_api\entity\location.py", line 249, in add_components
    transferred=transferred
ftrack_api.exception.LocationError: Failed to register components with location <UnmanagedLocation("ftrack.unmanaged", cb268ecc-8809-11e3-a7e2-20c9d081909b)> due to error:
    Server reported error: AttributeError('unicode' object has no attribute '_sa_instance_state')
    Transferred component data that may require cleanup: [(<dynamic ftrack FileComponent object 71112632>, 'P:\\a_project\\series_01\\sequences\\025\\sq025_sh040\\2d\\publish\\v009\\040_Compositing.nk')]

 

Link to post
Share on other sites

OK Solved it. I didn't realise I needed to pass an AssetType obj to the data used in the asset creation rather than the string name for the code.

shot = session.query('Shot where id is "bf127242-da0b-40aa-ac19-ca793f7590e0"').first()
typeObj = session.query('AssetType where short is "scene"').first()
data = {
    'parent': shot,
    'name':"aAsset",
    'type':typeObj,
}
asset = session.create("Asset", data)
Link to post
Share on other sites
  • 3 weeks later...

Hi I'm still having a few issues creating asset versions.

 

I've posted a snippet from my code bellow and the Error I'm getting. I'm having a hard time pin pointing whats happening here. Using the exact same code, sometimes this works and sometimes it errors.

I accept it probably is the case of sometimes the information I feed in to it causes it to error, however I'm not sure what in that case.  The section of the error "Duplicate entry '0704febd-acdb-4fc5-b212-c037039caf74-2' for key 'asset_version_assetid_key'" seems to suggest to me that I'm somehow attaching the AssetVersion twice to the Asset. Am I correct in interpreting this?

 

Overview of code bellow:

  • Get existing Asset or create one if none exists.
  • Create new AssetVersion and attach it to the asset.
  • Attach the thumbnail to the AssetVersion
  • Create a new component on the AssetVersion containing my publish File
  • Commit the session

 

assetType = session.query('AssetType where short is "scene"').first()
asset = session.query('Asset where name is "{0}"'.format(assetName)).first()

try:
    if not asset:
        data = {
            'parent': lemonEngine.currentContext.shot,
            'name': assetName,
            'type': assetType,
        }
        asset = session.create("Asset", data)

    data = {
        "task":lemonEngine.currentContext.task,
        "asset": asset,
        "name":assetName,
        "version":publishVersion,
        "comment":description
    }
    assetVersion = session.create("AssetVersion",data)

    if thumbnail:
        tempFile = pc.get_temp_thumbnail(thumbnail)
        assetVersion.create_thumbnail(tempFile.fileName())
        tempFile.remove()

    assetVersion.create_component(publishFile,
                                  data={'name':assetName},
                                  location=location)

    session.commit()
except:
    session.rollback()
    raise
Failed to register components with location <Location("ftrack.server", 3a372bde-05bc-11e4-8908-20c9d081909b)> due to error:
Server reported error: IntegrityError((IntegrityError) (1062, "Duplicate entry '0704febd-acdb-4fc5-b212-c037039caf74-2' for key 'asset_version_assetid_key'") 'INSERT INTO asset_version (id, asset_id, thumbnail_id, version, comment, date, user_id, task_id, is_published, status_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' (u'7da43300-b4d6-4159-96fb-4c2525ba6d7e', '0704febd-acdb-4fc5-b212-c037039caf74', None, 2, '', datetime.datetime(2016, 8, 12, 11, 39, 15, 498604), None, '2b659258-8d44-4018-b1b9-9c096c892d28', 1, None))
Transferred component data that may require cleanup: [(<dynamic ftrack FileComponent object 2841717392>, '33adc5ee-90cd-4e4b-a3b0-21980c3efc8e')]

 

Link to post
Share on other sites

I think I know what is happening. A change in our config means our publish files are saving to another location, and starting the version again. So its trying to create v1 when it already exists.

I should check ftrack for the latest version as well as on disk to make sure that, I have the highest possible version first.

Link to post
Share on other sites

Having done this I'm still running into the same Issue.

I am now trying to create v18 and there is only a v17 in ftrack, yet I am still getting the same error.

Can anyone explain exactly what the error is trying to tell me? I get that its probably happening when I do 

assetVersion.create_component(publishFile,
                                  data={'name':assetName},
                                  location=location)

I'm not sure what the rules are here, but I must be trying to duplicate something that is not allowed. The asset is preexisting (but should be resused I think?), the assetVersion is new, the component is trying to be newly created. Perhaps the path has been registered already, could it be trying to tell me this?

I also don't understand this part:

Transferred component data that may require cleanup: [(<dynamic ftrack FileComponent object 2841717392>, '33adc5ee-90cd-4e4b-a3b0-21980c3efc8e')]

 

Thanks

Phil

Link to post
Share on other sites
  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...