UserMetadata and GET response when undefined

First, for some reason, searching UserMetadata in the forum pulls up many many posts that don’t mention UserMetadata. So, I apologize if this has already been discussed.

I am experimenting with the UserMetadata configuration to define a simple boolean property that I will assign to series.

I define the UserMetadata in my config.json file (actually by way of ORTHANC__USER_METADATA and the osimis docker image).

I find that if I query a given series BEFORE actually setting the value, a 404 error is generated in Firefox. In the python plugin context (orthanc.RestAPIGet), the get request fails with an internal error crashing out of Python and is only recoverable if wrapped in a try/except.

Is this by design? Is the general practice then to first check for the existence of the metadata with a call to /metadata? Rather than calling /metadata/MyMeta? I’m ok with that, but wanted to clarify that this is the intended behavior.

Thanks,
John.

Hello,

Yes, in Python, a call to “orthanc.RestApiGet()” to an nonexistent resource always raises an exception.

This is because the “orthanc” Python module is automatically generated from the C SDK. In your case, this function is wrapped from “OrthancPluginRestApiGet()”:
https://sdk.orthanc-server.com/group__Orthanc.html#ga9fdcf0181b1f0a18c5e4c9fa2dd71cc4

If the function doesn’t return “OrthancPluginErrorCode_Success” (in your case, the function actually returns “OrthancPluginErrorCode_UnknownResource”), the wrapper generates an exception, as can be read in the source code:
https://hg.orthanc-server.com/orthanc-python/file/e7ff5efb100d/Sources/Autogenerated/sdk_GlobalFunctions.impl.h#l127

Note that the behavior has recently be improved: In releases <= 3.2 of the Python plugin, the Python plugin raises the “ValueError” built-in exception (which doesn’t provide a way to access to actual error code), whereas in future releases, the Python plugin will raise the custom exception “orthanc.OrthancException” (that gives access to the actual error code):
https://book.orthanc-server.com/plugins/python.html#catching-exceptions
https://groups.google.com/g/orthanc-users/c/pxMd742aSsU/m/XtU6aqxqBQAJ

HTH,
Sébastien-

Thanks, Sebastien, for clarifying that.
John.