Page 1 of 1

getObject inquiry

PostPosted: Thu Feb 23, 2012 1:58 am
by icaoberg
I am aware that the method getObject will return empty if the object is not found. but, are there any situations other than a closed connection where this method might throw an exception?

ivan

Re: getObject inquiry

PostPosted: Thu Feb 23, 2012 8:00 am
by wmoore
Hi,

conn.getObject() is expected to return a single item. It will throw an exception if more than one object is returned, since it uses queryService.findByQuery(query, params)

E.g.
Code: Select all
conn.getObject("Image", attributes={"name", "myImage.tiff"})


will throw if there is more than one image of that name.

It will also throw an AttributeError if the string is not supported. Supported strings are mapped to the wrapper used to wrap the returned object. They are, by default:

Code: Select all
KNOWN_WRAPPERS.update({"project":ProjectWrapper,
                  "dataset":DatasetWrapper,
                  "image":ImageWrapper,
                  "screen":ScreenWrapper,
                  "plate":PlateWrapper,
                  "plateacquisition": PlateAcquisitionWrapper,
                  "well":WellWrapper,
                  "experimenter":ExperimenterWrapper,
                  "experimentergroup":ExperimenterGroupWrapper,
                  "originalfile":OriginalFileWrapper,
                  "commentannotation":CommentAnnotationWrapper,
                  "tagannotation":TagAnnotationWrapper,
                  "longannotation":LongAnnotationWrapper,
                  "booleanannotation":BooleanAnnotationWrapper,
                  "fileannotation":FileAnnotationWrapper,
                  "doubleannotation":DoubleAnnotationWrapper,
                  "termannotation":TermAnnotationWrapper,
                  "timestampannotation":TimestampAnnotationWrapper,
                  "annotation":AnnotationWrapper._wrap})