Description
Capi.setValue/setString() does not encode the string value. As a result, when setValue() receives a Python str instead of bytes, it causes string assignments through the Python API to fail.
The issue seems to be inside Capi.setString().
The function is implemented in capi.py as
def setString(self, cref, value):
'''Set a string value for a model or system.'''
status = self.obj.oms_setString(cref.encode(), value)
return Status(status)
Notice that cref is encoded, while value is passed unchanged.
Expected behavior
String values should be encoded before being forwarded to the ctypes binding:
if isinstance(value, str):
value = value.encode()
This would make string handling consistent with the encoding already performed for cref.
N/A
Version and OS
- Version: master
- OS: Ubuntu 24.04
Description
Capi.setValue/setString()does not encode the string value. As a result, whensetValue()receives a Pythonstrinstead ofbytes, it causes string assignments through the Python API to fail.The issue seems to be inside
Capi.setString().The function is implemented in
capi.pyasNotice that
crefis encoded, whilevalueis passed unchanged.Expected behavior
String values should be encoded before being forwarded to the ctypes binding:
This would make string handling consistent with the encoding already performed for
cref.N/A
Version and OS