Repository: just-work/fffw

Issue:
Filter._clone changes attribute types
`Upload._clone()` method changes `device` type from `Device` to `dict`. After that upload instance become unusable.

Discussion:

Patch:
diff --git a/fffw/encoding/filters.py b/fffw/encoding/filters.py
index 1f49262..ba3dba6 100644
--- a/fffw/encoding/filters.py
+++ b/fffw/encoding/filters.py
@@ -422,6 +422,12 @@ class Upload(VideoFilter):
     extra_hw_frames: int = param(default=64, init=False)
     device: Device = param(skip=True)
 
+    def __post_init__(self) -> None:
+        if isinstance(self.device, dict):
+            # deserialize back after filter cloning
+            self.device = Device(**self.device)
+        super().__post_init__()
+
     def transform(self, *metadata: Meta) -> VideoMeta:
         """ Marks a stream as uploaded to a device."""
         meta = ensure_video(*metadata)


Test patch:
diff --git a/tests/test_graph.py b/tests/test_graph.py
index c7db0fd..93b4ffc 100644
--- a/tests/test_graph.py
+++ b/tests/test_graph.py
@@ -389,6 +389,15 @@ class FilterGraphTestCase(TestCase):
         except ValueError:  # pragma: no cover
             self.fail("hardware validation unexpectedly failed")
 
+    def test_upload_filter_clone(self):
+        """ While cloning Upload filter should preserve Device instance."""
+        cuda = meta.Device(hardware='cuda', name='foo')
+        upload = self.source.video | Upload(device=cuda)
+
+        upload = upload.clone(2)[1]
+        vm = cast(VideoMeta, upload.meta)
+        self.assertEqual(vm.device, cuda)
+
     def test_codec_metadata_transform(self):
         """
         Codecs parameters applied to stream metadata when using transform.