fix(symbol-config): coerce int->SymbolAccess via type(maximal_access) (#9)
Second bug found live on MCPTest after the get_only_configured_signatures fix landed. When _resolve_access falls back to int (because 'from scriptengine import SymbolAccess' returned a hollow class on this SP), the C# setter for ScriptSymbolConfigVariable.configured_access rejects every non-zero int with: TypeError: Cannot convert numeric value 1 to SymbolAccess. The value must be zero. (only 0=None passes the implicit conversion). Recover by taking the enum class from v.maximal_access -- always populated as a genuine SymbolAccess value -- and re-parsing the int through it: enum_cls(int_value). Verified live on MCPTest under SP22 P1: PLC_PRG.fb -> ReadOnly succeeds where it previously errored. Same coercion applied to set_signature_access_bulk (lazily on the first variable in the loop, since requested_access is shared across all variables in a bulk run). Co-authored-by: Karstein Phobic Nyvold Kvistad <karstein.kvistad@maritimerobotics.com>
This commit is contained in:
parent
5ea04a2003
commit
507cae0020
1 changed files with 15 additions and 0 deletions
|
|
@ -104,6 +104,13 @@ try:
|
|||
raise RuntimeError(
|
||||
"Signature '%s' not found (library_id=%s)." % (SIGNATURE_FQN, LIBRARY_ID or '<none>'))
|
||||
|
||||
# If _resolve_access fell back to a plain int (because `from scriptengine
|
||||
# import SymbolAccess` returned a hollow object on this SP), the C#
|
||||
# setter rejects every non-zero int with "Cannot convert numeric value
|
||||
# N to SymbolAccess. The value must be zero." -- only 0 (=None) survives
|
||||
# the implicit conversion. Recover lazily on the first variable: take
|
||||
# the enum class from v.maximal_access (always a genuine SymbolAccess
|
||||
# value) and re-parse the int through it.
|
||||
changed = []
|
||||
skipped = []
|
||||
try:
|
||||
|
|
@ -112,6 +119,14 @@ try:
|
|||
v_name = v.name
|
||||
except Exception:
|
||||
v_name = '?'
|
||||
if isinstance(requested_access, int):
|
||||
try:
|
||||
enum_cls = type(v.maximal_access)
|
||||
requested_access = enum_cls(requested_access)
|
||||
print("DEBUG: int->enum coerced via type(v.maximal_access): %r"
|
||||
% requested_access)
|
||||
except Exception as e:
|
||||
print("DEBUG: int->enum coercion failed: %s" % e)
|
||||
try:
|
||||
v.configured_access = requested_access
|
||||
changed.append(v_name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue