# Python SDK Serializer error

**URL:** <https://forum.opentap.io/t/python-sdk-serializer-error/1014>\
**Category:** General\
**Created:** [February 2, 2023, 6:34pm UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014 "2023-02-02T18:34:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davihous](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@davihous](https://forum.opentap.io/u/davihous)\
**Post date:** [February 2, 2023, 6:34pm UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014/1 "2023-02-02T18:34:56Z")

</div>

I am getting errors of this type for properties on my step. The errors occur when the step is added to the test plan

Serializer ; Error ; Unable to serialize property ‘iteration’.  
Serializer ; Debug ; PythonException: \<method ‘get’ of ‘dict’ objects\> returned a result with an exception set  
Serializer ; Debug ; File “C:\Users\PRODCON2\AppData\Local\Programs\Python\Python310\lib\weakref.py”, line 453, in get  
Serializer ; Debug ; return self.data.get(ref(key),default)  
Serializer ; Debug ; File “”, line 90, in **get**  
Serializer ; Debug ; at Python.Runtime.PythonException.ThrowLastAsClrException()  
Serializer ; Debug ; at Python.Runtime.PyObject.GetAttr(String name)  
Serializer ; Debug ; at Python.Runtime.PythonDerivedType.InvokeGetProperty[T](IPythonDerivedType obj, String propertyName)  
Serializer ; Debug ; at lambda\_method(Closure , Object )  
Serializer ; Debug ; at OpenTap.Plugins.ObjectSerializer.Serialize(XElement elem, Object obj, ITypeData expectedType)  
Serializer ; Debug ; Inner PythonException: unhashable type  
Serializer ; Debug ; Exception caught at:  
Serializer ; Debug ; at Void Serialize(System.Xml.XmlWriter, System.Object)  
Serializer ; Debug ; at Void Serialize(System.IO.Stream, System.Object)  
Serializer ; Debug ; at Void Save(System.IO.Stream)  
Serializer ; Debug ; at Void d(System.Threading.Tasks.Task)  
Serializer ; Debug ; …

The step is written in Python, and the property that is throwing the error is declared as:

iteration = property(OpenTap.Input[Decimal], None)  
.add\_attribute(Browsable(False))

where Decimal is a C# System.Decimal type. In **init** () the property is initialized similarly:

self.iteration = OpenTap.InputDecimal

These errors occur for other similar properties as well. What is this error saying and is there a way to fix this serialization error?

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [February 2, 2023, 9:29pm UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014/2 "2023-02-02T21:29:10Z")

</div>

I wonder why it claims it is an ‘unhashable’ type. Seems perfectly hashable to me.

- Does this issue reproduce with Input?
- Are you initializing `iteration` in the constructor of your class? e.g. `self.iteration = OpenTap.Input[Decimal]()`?

---

<div class="post-metadata">

**Author:** ![davihous](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@davihous](https://forum.opentap.io/u/davihous)\
**Post date:** [February 2, 2023, 11:52pm UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014/3 "2023-02-02T23:52:18Z")

</div>

After some investigation it appears to impact properties declared with C# types. Including Int32, Decimal and Duts. It seems to happen when these properties are parameterized.

We have also determined that the failure first occurs after the init runs (the step is added to the test plan) and it isn’t consistent. Adding one step may not throw any errors, but adding multiple of the same step usually guarantees these errors will generate. Additionally, the errors are not always shown by the step that has just been added; often it is a step that was added previously that the error occurs in.

Below you can see one of the errors that popped up  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/opentap/original/1X/e51f3de712a88e281b434770d5ec19e4a357171d.png)

An additional note is it happens in 9.19.5+ and doesn’t happen in 9.18.5

---

<div class="post-metadata">

**Author:** ![davihous](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@davihous](https://forum.opentap.io/u/davihous)\
**Post date:** [February 3, 2023, 1:01am UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014/4 "2023-02-03T01:01:57Z")

</div>

I have made a simple example that will fail when adding several of “Fancy Plan Step”

```csharp
import opentap
from opentap import attribute, property

import OpenTap
from OpenTap import *
from OpenTap.Plugins import BasicSteps
from System import Int32

@attribute(OpenTap.Display("Fancy Delay", "", Groups=["Some Group", "Step"]))
class FancyDelay(BasicSteps.DelayStep): 
    FancyTime = property(Int32, 0)
    
    def __init__ (self):
        super(FancyDelay, self). __init__ () 

@attribute(OpenTap.Display("Fancy Plan Step", "", Groups=["Some Group", "PlanStep"]))
class FancyPlanStep(BasicSteps.SequenceStep): 
    def __init__ (self):
        super(FancyPlanStep, self). __init__ () 
        
        timesweep = BasicSteps.SweepParameterStep()
        delaystep = FancyDelay()

        self.ChildTestSteps.Add(timesweep)
        timesweep.ChildTestSteps.Add(delaystep)

        member = OpenTap.TypeData.GetTypeData(delaystep).GetMember("FancyTime")
        OpenTap.ParameterExtensions.Parameterize(member, timesweep, delaystep, "FancyTime")

        for i in range(10):
            sweepRow = OpenTap.Plugins.BasicSteps.SweepRow()
            sweepRow.Enabled = True
            sweepRow.Loop = timesweep
            sweepRow.Values.Add("FancyTime", i)
            timesweep.SweepValues.Add(sweepRow)

    def Run(self):
        super().Run()

```

The error I am getting is

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opentap/original/1X/500e4245f56118df6f5aee5c92d3cf1a6174b330.png)

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [February 3, 2023, 6:45am UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014/5 "2023-02-03T06:45:58Z")

</div>

Ok. To me it seems like there is an issue with programatically adding a step to a sweep inside of a constructor.

Did you notice it in other scenarios as well?

---

<div class="post-metadata">

**Author:** ![davihous](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@davihous](https://forum.opentap.io/u/davihous)\
**Post date:** [February 6, 2023, 4:15pm UTC](https://forum.opentap.io/t/python-sdk-serializer-error/1014/6 "2023-02-06T16:15:12Z")

</div>

If I adjust the code so that the steps are added by a button instead it still causes the issue. It doesn’t always happen the first time but if I add enough of the steps and child steps I will get an issue

Here is the modified code

```csharp
@attribute(OpenTap.Display("Fancy Plan Step", "", Groups=["Some Group", "PlanStep"]))
class FancyPlanStep(BasicSteps.SequenceStep): 
    def __init__ (self):
        super(FancyPlanStep, self). __init__ () 
        
    @attribute(Browsable(True))
    @attribute(OpenTap.Display("Add Steps", None))
    @method()
    def add_steps(self):
        timesweep = BasicSteps.SweepParameterStep()
        delaystep = FancyDelay()

        self.ChildTestSteps.Add(timesweep)
        timesweep.ChildTestSteps.Add(delaystep)

        member = OpenTap.TypeData.GetTypeData(delaystep).GetMember("FancyTime")
        OpenTap.ParameterExtensions.Parameterize(member, timesweep, delaystep, "FancyTime")

        for i in range(10):
            sweepRow = OpenTap.Plugins.BasicSteps.SweepRow()
            sweepRow.Enabled = True
            sweepRow.Loop = timesweep
            sweepRow.Values.Add("FancyTime", i)
            timesweep.SweepValues.Add(sweepRow)

    def Run(self):
        super().Run()

```
