Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum arrays do not work with an empty default value #366

Open
bkeryan opened this issue Sep 1, 2023 · 0 comments
Open

Enum arrays do not work with an empty default value #366

bkeryan opened this issue Sep 1, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@bkeryan
Copy link
Collaborator

bkeryan commented Sep 1, 2023

Bug Report

Deserializing an enum array does not work when the configuration's default_value parameter is set to [] (empty list).

Repro or Code Sample

--- a/examples/sample_measurement/measurement.py
+++ b/examples/sample_measurement/measurement.py
@@ -55,6 +55,9 @@ class Color(Enum):
 @sample_measurement_service.configuration(
     "String Array In", nims.DataType.StringArray1D, ["String1", "String2"]
 )
+@sample_measurement_service.configuration(
+    "Enum Array In", nims.DataType.EnumArray1D, [], enum_type=Color
+)
 @sample_measurement_service.output("Float out", nims.DataType.Float)
 @sample_measurement_service.output("Double Array out", nims.DataType.DoubleArray1D)
 @sample_measurement_service.output("Bool out", nims.DataType.Boolean)
@@ -72,6 +75,7 @@ def measure(
     enum_input,
     protobuf_enum_input,
     string_array_in,
+    enum_array_in,
 ):
     """Perform a loopback measurement with various data types."""
     logging.info("Executing measurement")
@@ -81,6 +85,8 @@ def measure(

     sample_measurement_service.context.add_cancel_callback(cancel_callback)

+    logging.info("enum_array_in: %r", enum_array_in)
+
     float_output = float_input
     float_array_output = double_array_input
     bool_output = bool_input

Steps:

  • Open MeasurementLink UI Editor.
  • Drop a Numeric Array Input.
  • Bind it to Enum Array In.
  • Set the first element to 1.
  • Run the measurement.

Expected Behavior

The measurement logs this message:

enum_array_in: [<Color.RED: 1>]

Current Behavior

The measurement produces this error:

PS D:\dev\measurementlink-python\examples\sample_measurement> poetry run python .\measurement.py -v
2023-09-01 17:48:26,593 INFO: Measurement service hosted on port: 52794
2023-09-01 17:48:27,123 INFO: Successfully registered with discovery service.
Press enter to close the measurement service.
2023-09-01 17:49:09,385 INFO: gRPC server call /ni.measurementlink.measurement.v2.MeasurementService/GetMetadata responded OK in 0.9639 ms
2023-09-01 17:50:07,890 INFO: gRPC server call /ni.measurementlink.measurement.v2.MeasurementService/Measure responded OK in 0.6051 ms
2023-09-01 17:50:07,890 ERROR: Exception iterating responses: 'int' object is not iterable
Traceback (most recent call last):
  File "D:\dev\measurementlink-python\examples\sample_measurement\.venv\lib\site-packages\grpc\_server.py", line 589, in _take_response_from_response_iterator
    return next(response_iterator), True
  File "D:\dev\measurementlink-python\ni_measurementlink_service\_loggers.py", line 391, in __next__
    response = next(self._inner_iterator)
  File "D:\dev\measurementlink-python\ni_measurementlink_service\_internal\grpc_servicer.py", line 385, in Measure
    mapping_by_id = serializer.deserialize_parameters(
  File "D:\dev\measurementlink-python\ni_measurementlink_service\_internal\parameter\serializer.py", line 41, in deserialize_parameters
    _deserialize_enum_parameters(parameter_metadata_dict, overlapping_parameter_by_id)
  File "D:\dev\measurementlink-python\ni_measurementlink_service\_internal\parameter\serializer.py", line 231, in _deserialize_enum_parameters
    parameter_by_id[id][index] = enum_type(member_value)
TypeError: 'int' object is not iterable

Workaround

Make the default value non-empty (e.g. [Color.BLUE]).

Possible Solution

I think we should save the passed-in enum_type and use it during deserialization, instead of using the type of the default value.

Inferring the enum type from the default value as described in #364 could still work, but not when the default value is an empty list.

Context

#364

Your Environment

  • OS & Device: Windows
  • ni-measurementlink-service version: 1.1.0, 1.2 main branch
  • MeasurementLink version: 2023 Q3 (23.5)
  • Python version: 3.9.13

AB#2509973

AB#2514631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants