If anyone has experience debugging Embedded Python or has insight into why an ObjectScript method when called from a Python method would not work but would work when called directly via ObjectScript or in a Python shell, your help would be appreciated!
We have an ObjectScript ClassMethod called GetTemplateString() which takes in a templateName of String type and uses the template name to get the template object, access the Code, and read the code into a templateString. The string version of the Code is returned.
ClassMethod GetTemplateString(templateName As %String) As %String
{
set template = ##class(%Library.RoutineMgr).%OpenId(templateName)
set templateString = template.Code.Read()
return templateString
}
This method works as expected when called directly from ObjectScript in an IRIS terminal and also works when called directly from an IRIS terminal in the Python shell. In both cases the expected string value of the template Code contents is returned.
However, we need to call the GetTemplateString method from inside a Language = python type ClassMethod. When we call the method from within the Python class using iris.cls() an empty string is the returned value for templateString.
ClassMethod MergeInternal(templateName As %String, templateString As %String) As %Stream.Object [ Language = python ]
{
import iris
class IRISLoader:
def load_text(self, name):
templateString = iris.cls('pkg.isc.airspeed.API').GetTemplateString(name)
return templateString
def load_template(self, name):
template = Template(self.load_text(name), filename=name)
return template
...
}
In debugging, we have confirmed using CodeGetSwizzled(1) that the Code has been swizzled, but Code when Read() always returns an empty string when called in this way. We are unsure why this is happening when the method is called from within the python ClassMethod.
Does anyone have ideas or insight that could assist us in our debugging efforts? Thank you!