diff --git a/src/videoag_common/api_object/object_class.py b/src/videoag_common/api_object/object_class.py
index aff041aa09d845341fce0cfefe5743e383317adb..12db9003747256917f22d714f430b4d4bf796856 100644
--- a/src/videoag_common/api_object/object_class.py
+++ b/src/videoag_common/api_object/object_class.py
@@ -333,10 +333,10 @@ class ApiObjectClass:
         context = getattr(args, context_name)
         if not isinstance(context, dict):
             raise Exception(f"serialization argument '{context_name}' must be a dict")
-        if str(self.id) not in context:
-            context[str(self.id)] = None  # Indicate that object is being serialized. Prevent loops
-            context[str(self.id)] = self.serialize_object_args(obj, args, to_context=False)
-        return self.id
+        if str(obj.id) not in context:
+            context[str(obj.id)] = None  # Indicate that object is being serialized. Prevent loops
+            context[str(obj.id)] = self.serialize_object_args(obj, args, to_context=False)
+        return obj.id
     
     def get_creation_config(self) -> JsonTypes or None:
         if not self.enable_config: