Repository: AcademySoftwareFoundation/rez

Issue:
Package orderes are wrong type when context generate from .rxt
Package orderes are wrong type when context generated from .rxt (ResolvedContext.from_dict())
https://github.com/AcademySoftwareFoundation/rez/blob/a2abe1a43a6bbac9fd76e41343ed120744a6d5b3/src/rez/resolved_context.py#L1700
`r.package_orderers` is set to builtin.List
when it should be `rez.package_order.PackageOrderList`
https://github.com/AcademySoftwareFoundation/rez/blob/a2abe1a43a6bbac9fd76e41343ed120744a6d5b3/src/rez/resolved_context.py#L240

Generally `package_orderers` is `None` by default, so issue is not seen, and most use cases dont have a context coming from a .rxt to a .rxt.

**Environment**
* Linux Rocky 9
* Rez version 3.2.1
* Rez python version 3.11

**To Reproduce**
1. Set a package orderer in rez settings
2. Try and create a bundle

**Expected behavior**
Bundle should be created

**Actual behavior**
Fails at the end when it tries to generate context.rxt
```
Traceback (most recent call last):
  File "/opt/rez/bin/rez/rez-bundle", line 8, in <module>
    sys.exit(run_rez_bundle())
             ^^^^^^^^^^^^^^^^
  File "/opt/rez/lib64/python3.11/site-packages/rez/cli/_entry_points.py", line 267, in run_rez_bundle
    return run("bundle")
           ^^^^^^^^^^^^^
  File "/opt/rez/lib64/python3.11/site-packages/rez/cli/_main.py", line 189, in run
    returncode = run_cmd()
                 ^^^^^^^^^
  File "/opt/rez/lib64/python3.11/site-packages/rez/cli/_main.py", line 181, in run_cmd
    return func(opts, opts.parser, extra_arg_groups)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/rez/lib64/python3.11/site-packages/rez/cli/bundle.py", line 47, in command
    bundle_context(
  File "/opt/rez/lib64/python3.11/site-packages/rez/bundle_context.py", line 59, in bundle_context
    bundler.bundle()
  File "/opt/rez/lib64/python3.11/site-packages/rez/bundle_context.py", line 102, in bundle
    self._write_retargeted_context(relocated_package_names)
  File "/opt/rez/lib64/python3.11/site-packages/rez/bundle_context.py", line 187, in _write_retargeted_context
    bundled_context = self.context.retargeted(
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/rez/lib64/python3.11/site-packages/rez/resolved_context.py", line 509, in retargeted
    d = self.to_dict()
        ^^^^^^^^^^^^^^
  File "/opt/rez/lib64/python3.11/site-packages/rez/resolved_context.py", line 1538, in to_dict
    data["package_orderers"] = self.package_orderers.to_pod()
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'to_pod'
```

Discussion:
@vanridal: Pull Request for issue
https://github.com/AcademySoftwareFoundation/rez/pull/1985

Solution patch:
diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py
index 98082242..8ad89fe2 100644
--- a/src/rez/resolved_context.py
+++ b/src/rez/resolved_context.py
@@ -1697,7 +1697,7 @@ class ResolvedContext(object):
 
         data = d.get("package_orderers")
         if data:
-            r.package_orderers = [package_order.from_pod(x) for x in data]
+            r.package_orderers = PackageOrderList([package_order.from_pod(x) for x in data])
         else:
             r.package_orderers = None
 


Test patch:
diff --git a/src/rez/tests/test_context.py b/src/rez/tests/test_context.py
index 9c2467c6..82786f04 100644
--- a/src/rez/tests/test_context.py
+++ b/src/rez/tests/test_context.py
@@ -278,6 +278,35 @@ class TestContext(TestBase, TempdirMixin):
         resolved = [x.qualified_package_name for x in r.resolved_packages]
         self.assertEqual(resolved, ['python-2.7.0'])
 
+    def test_serialize_roundtrip_with_extra_settings(self):
+        from rez.package_order import VersionSplitPackageOrder
+        from rez.version import Version
+
+        packages_path = self.data_path("solver", "packages")
+
+        file = os.path.join(self.root, "roundtrip.rxt")
+        orderers = [VersionSplitPackageOrder(Version("2.6.8"))]
+        r1 = ResolvedContext(
+            ["python"],
+            package_orderers=orderers,
+            package_paths=[packages_path],
+        )
+        r1.save(file)
+        r2 = ResolvedContext.load(file)
+
+        self.assertEqual(r1, r2)
+
+        ignored_properties = [
+            'load_path',
+            'graph_string',
+            'graph_'
+        ]
+        for k, v in r1.__dict__.items():
+            if k in ignored_properties:
+                continue
+            # check types here, as not all type instances are comparable
+            self.assertIs(type(v), type(r2.__dict__.get(k)))
+
 
 if __name__ == '__main__':
     unittest.main()