Skip to content

setString issue #1620

Description

@JackCaster

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions