From 5ea04a200305a57c1dbb04a477aec32c48eb0515 Mon Sep 17 00:00:00 2001 From: Karstein Phobic Nyvold Kvistad Date: Wed, 29 Apr 2026 10:21:27 +0200 Subject: [PATCH] fix(symbol-config): coerce int access to genuine enum via type(maximal_access) When _resolve_access falls back to a plain int (because the 'from scriptengine import SymbolAccess' import returned a hollow object on this SP), the C# setter rejects every non-zero int: Cannot convert numeric value N to SymbolAccess. The value must be zero. Only 0 (=None) survives the implicit conversion. Recover by parsing the int through the enum class type we just got from var.maximal_access (which is always a genuine SymbolAccess value because it came back through the same scriptengine that's about to accept it). DEBUG print for both the success and failure paths. --- src/scripts/set_symbol_access.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/scripts/set_symbol_access.py b/src/scripts/set_symbol_access.py index f54eba8..4937a0f 100644 --- a/src/scripts/set_symbol_access.py +++ b/src/scripts/set_symbol_access.py @@ -177,6 +177,21 @@ try: print("DEBUG: maximal_access=%s, configured_access(before)=%s" % ( max_access, getattr(var, 'configured_access', '?'))) + # 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 by parsing the int through the enum + # class type we just got from var.maximal_access (which is always a + # genuine SymbolAccess value). + if isinstance(requested_access, int) and max_access is not None: + try: + enum_cls = type(max_access) + requested_access = enum_cls(requested_access) + print("DEBUG: int->enum coerced via type(maximal_access): %r" % requested_access) + except Exception as e: + print("DEBUG: int->enum coercion via type(maximal_access) failed: %s" % e) + var.configured_access = requested_access # Verify post-set state.