Silly me - 'misc_info' shows up in the show() output, but I didn't bother to verify that it was metadata and not some other member. Thanks! John Duddy Sr. Staff Software Engineer Illumina, Inc. 9885 Towne Centre Drive San Diego, CA 92121 Tel: 858-736-3584 E-mail: jduddy@illumina.com -----Original Message----- From: Nate Coraor [mailto:nate@bx.psu.edu] Sent: Monday, May 09, 2011 8:27 AM To: Duddy, John Cc: galaxy-dev@lists.bx.psu.edu Subject: Re: [galaxy-dev] Unable to set metadata in API call Duddy, John wrote:
I need to be able to set some metadata in some custom data types. For now, I'm just trying to set the value of the 'misc_info' field. The client script is this: put( sys.argv[1], sys.argv[2], { 'update_type' : 'metadata', 'misc_info' : 'meta data msg' } ) and my API method is as follows. It executes fine, but the values do not show on the next show() call.
Hi John, Your method below works fine for existing metadata items like 'data_lines', so I suspect the problem is not with the update method, but with the datatype definition. Does your class have a 'misc_info' MetadataElement? --nate
Disclaimer: Python is still quite new to me, and it's very likely I do not understand the metadata model and the way library dataset associates work.
Any clues will be greatly appreaciated! @web.expose_api def update( self, trans, id, library_id, payload, **kwd ): """ PUT /api/libraries/{encoded_library_id}/contents/{encoded_content_type_and_id} Sets attributes (metadata) on a library item. """ update_type = None if 'update_type' not in payload: trans.response.status = 400 return "Missing required 'update_type' parameter. Please consult the API documentation for help." else: update_type = payload.pop( 'update_type' ) if update_type not in ( 'metadata' ): trans.response.status = 400 return "Invalid value for 'update_type' parameter ( %s ) specified. Please consult the API documentation for help." % update_type content_id = id decoded_type_and_id = trans.security.decode_string_id( content_id ) content_type, decoded_content_id = decoded_type_and_id.split( '.' ) if content_type not in ( 'file' ): trans.response.status = 400 return "Updates allowed only on files, not directories" try: content = trans.sa_session.query( trans.app.model.LibraryDatasetDatasetAssociation ).get( decoded_content_id ) except: content = None if not content or ( not trans.user_is_admin() and not trans.app.security_agent.can_modify_library_item( trans.get_current_user_roles(), content, trans.user ) ): trans.response.status = 400 return "Invalid %s id ( %s ) specified." % ( content_type, str( content_id ) )
metadata = content.get_metadata() content.datatype.before_setting_metadata(content)
if not metadata: metadata = {}
for name in payload: if name not in [ 'name', 'info', 'dbkey' ]: setattr( metadata, name, payload[name])
content.set_metadata(metadata) content.datatype.after_setting_metadata( content ) trans.sa_session.flush()
return "OK"
John Duddy Sr. Staff Software Engineer Illumina, Inc. 9885 Towne Centre Drive San Diego, CA 92121 Tel: 858-736-3584 E-mail: jduddy@illumina.com<mailto:jduddy@illumina.com>
___________________________________________________________ Please keep all replies on the list by using "reply all" in your mail client. To manage your subscriptions to this and other Galaxy lists, please use the interface at: