Skip to content

Commit 95bc073

Browse files
committed
[Docs] Add DR002 for versioning in codegen
Part of OpenAssetIO#88. Consolidate the discussion, provoked by iterations of the design proposal in OpenAssetIO#90, into a decision record. Signed-off-by: David Feltell <[email protected]>
1 parent f20a2c4 commit 95bc073

File tree

1 file changed

+231
-0
lines changed

1 file changed

+231
-0
lines changed
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# DR025 Versioning Traits and Specification - generated view classes
2+
3+
- **Status:** Decided
4+
- **Impact:** High
5+
- **Driver:** @feltech
6+
- **Approver:** @elliotcmorris @themissingcow
7+
- **Outcome:** Traits and specifications will be versioned independent
8+
of the schema, there will be no concept of a schema version, and
9+
Trait/Specification view classes will be generated with version
10+
suffixes on the class name.
11+
12+
## Background
13+
14+
The medium of data exchange between a host and a manager is a logically
15+
opaque data blob, i.e. a `TraitsData` object. In order to extract
16+
information
17+
from this object, Trait and/or Specification view classes must be
18+
used[^1]. These classes wrap a `TraitsData` instance, and provide a
19+
suite of accessor and mutator methods that are relevant to the target
20+
trait. The classes are generated from a YAML schema (e.g. see
21+
[traits.yml](../traits.yml)).
22+
23+
Hosts and managers may use different versions of the schema, and hence
24+
different versions of the view classes, and yet still wish to work
25+
together.
26+
27+
This decision record follows on from a previous decision (OpenAssetIO
28+
[DR023](https://github.com/OpenAssetIO/OpenAssetIO/blob/main/doc/decisions/DR023-Versioning-traits-and-specifications-method.md))
29+
that communicating a trait's version should be done by bundling the
30+
version number with the data blob that is communicated across the API,
31+
i.e. within `TraitsData`, most likely by appending the version number to
32+
the unique trait ID.
33+
34+
With this previous decision in mind, we then need to decide on how the
35+
trait versions are represented in the high level interface, i.e. in
36+
the definition and usage of Trait/Specification view classes.
37+
38+
A motivating example should make this problem clear.
39+
40+
[^1]: In reality, a `TraitsData` is a simple dictionary-like structure,
41+
and the `TraitsData` type has a low-level interface for interacting with
42+
it, but usage of this is discouraged.
43+
44+
### Motivating example
45+
46+
An example usage of the current form of these generated classes might
47+
be:
48+
49+
```python
50+
url = LocatableContentTrait(trait_data).getLocation()
51+
```
52+
53+
Imagine that we want to rename the LocatableContent trait's `"location"`
54+
property to a more descriptive `"url"` property, hence changing the
55+
generated view class's method from `getLocation` to `getUrl`.
56+
57+
Given that hosts and managers are developed independently, we may end up
58+
with a situation where one side is setting `"location"` (using
59+
`setLocation`) in the data, handing it over to the other side, who then
60+
attempts to read `"url"` (using `getUrl`). I.e. we have a version
61+
mismatch.
62+
63+
There is therefore an incompatibility at the data layer (i.e. field
64+
names differ for the same semantic information). With C++, the data
65+
layer is where the incompatibility ends. The Trait/Specification view
66+
classes are private utility classes whose symbols should not be
67+
exported, so there will be no source or binary incompatibility.
68+
69+
However, with Python there is no such concept of a private, build-time
70+
only, class. The manager plugin and host application must use the same
71+
`openassetio-mediacreation` distribution package in the Python
72+
environment (not considering, for the moment, custom vendoring). So one
73+
side or the other will hit an `AttributeError` exception when trying to
74+
use a method from the version they developed against, rather than the
75+
version installed into the environment.
76+
77+
In order to interoperate, previous versions of Trait/Specification view
78+
classes must be made available, so that fallback behaviour can be coded.
79+
In this example, the side that attempts to use the newer `getUrl` to
80+
read the data must be able to detect that it won't work and fall back to
81+
the previous version's `getLocation`.
82+
83+
### Assumptions
84+
85+
* A Trait/Specification view class is needed for each version, such
86+
that a user can imbue a particular version of a trait in some data;
87+
and can detect that a particular version of a trait is imbued in some
88+
data.
89+
* Trait unique IDs will be suffixed with a version number. This means
90+
two Trait view classes for the same trait, but for different versions,
91+
will be treated as if they are entirely separate traits.
92+
Version-agnostic utility functions may be added in the future, but it
93+
is out of scope for now.
94+
* If a Specification view class is used to construct/imbue a trait
95+
set/data, that data will _not_ have the Specification version encoded
96+
in the data directly (only implicitly through the versioned IDs of the
97+
composite traits).
98+
99+
## Relevant data
100+
101+
[OpenTimelineIO schema
102+
versioning](https://opentimelineio.readthedocs.io/en/latest/tutorials/otio-file-format-specification.html#example)
103+
is perhaps the closest analog. The version of the schema is appended to
104+
the schema ID whenever it appears within a OTIO JSON document.
105+
106+
The options presented were arrived at by sketching a proposal in [a Pull
107+
Request](https://github.com/OpenAssetIO/OpenAssetIO-MediaCreation/pull/90),
108+
soliciting feedback, and iterating. The final form of that PR reflects
109+
the chosen option.
110+
111+
## Options considered
112+
113+
### Option 1 - Per schema versioning
114+
115+
When traits or specifications in the YAML document are updated, a
116+
top-level schema version is incremented. During codegen, top-level
117+
namespaces are created by providing multiple YAML documents, one for
118+
each schema version.
119+
120+
For example
121+
122+
```python
123+
from openassetio_mediacreation.v1.traits.content import LocatableContent as LocatableContent_v1
124+
from openassetio_mediacreation.v2.traits.content import LocatableContent as LocatableContent_v2
125+
from openassetio_mediacreation.v2.specifications.twoDimensional import ImageSpecification
126+
```
127+
128+
#### Pros
129+
130+
- Tantalising possibility to use [Python namespace
131+
packages](https://packaging.python.org/en/latest/guides/packaging-namespace-packages)
132+
to allow different schema versions to be installed independently
133+
side-by-side.
134+
- The schema version a specification comes from instantly tells you the
135+
schema version of the constituent traits.
136+
- The YAML is kept small and focussed just on the latest versions.
137+
- Minimal changes to the `traitgen` tool and existing YAML documents.
138+
- Maintaining only the latest versions in the live YAML document
139+
prevents accidental changes to old versions that could break backward
140+
compatibility.
141+
- The consumer is in charge of deciding which versions they support.
142+
I.e. once a host/manager determines that they no longer wish to
143+
support a particular version, they can stop
144+
generating/installing/bundling subpackages for it.
145+
- Once it is clear that a host/manager understands a particular schema
146+
version (via `managementPolicy` or otherwise), the communicating
147+
manager/host can be confident in using that schema version for other
148+
traits/specifications.
149+
150+
#### Cons
151+
152+
- A source-incompatible breaking change, unless significant
153+
special-casing is added.
154+
- Verbose when using two versions in the same source file, either
155+
requiring use of qualified names (e.g. `v1.traits.LocatableContent`)
156+
or additional aliasing (e.g.
157+
`from ... import LocatableContent as LocatableContent_v1`).
158+
- Not clear at-a-glance which traits have changed between schema
159+
versions, e.g. it's not clear if
160+
`v2.traits.content.LocatableContentTrait` is the same as
161+
`v1.traits.content.LocatableContentTrait`.
162+
- Must compare multiple YAML documents side-by-side in order to discover
163+
the history of changes to a particular trait/specification.
164+
- Traits/specifications that are unchanged between versions implies
165+
duplicated code across namespaces (though likely simply aliased).
166+
- Independently generated/installed subpackages for each schema version
167+
would mean that deprecation warnings could not be added to old
168+
versions. This is mitigated if multiple versions are generated
169+
together, where the older version can be detected and deprecation
170+
warnings added by codegen.
171+
172+
### Option 2 - Per Trait/Specification versioning
173+
174+
A single YAML document is maintained, where each trait/specification
175+
definition branches off into a list of versions. Old
176+
trait/specification versions can be marked as deprecated and removed
177+
eventually, to prevent infinite growth.
178+
179+
For example
180+
181+
```python
182+
from openassetio_mediacreation.traits.content import LocatableContent_v1
183+
from openassetio_mediacreation.traits.content import LocatableContent_v2
184+
from openassetio_mediacreation.specifications.twoDimensional import ImageSpecification_v2
185+
```
186+
187+
#### Pros
188+
189+
- Fairly trivial to say that the first version "`_v1`" is equivalent to
190+
"" (blank), and to ensure that v1's trait ID doesn't contain a version
191+
tag, then e.g. the `LocatableContent` class continues to work as
192+
before versioning was introduced, making this option fully source
193+
compatible with legacy code. I.e. not a breaking change.
194+
- Placing versions alongside one-another in the YAML definition allows
195+
easy discovery of the history of changes.
196+
- IDE code completion will list all versions of a Trait/Specification
197+
view class next to one-another.
198+
199+
#### Cons
200+
201+
- No indication of the version of the constituent traits from the
202+
version of a Specification view class.
203+
- Large change to `traitgen` tool and non-trivial breaking change to
204+
YAML documents.
205+
- Keeping old versions in a living document (as opposed to e.g. git
206+
history) is a potential source of accidental breakages to backward
207+
compatibility.
208+
- Generating all possible versions bloats an application's distribution,
209+
when it may only use a small subset of them.
210+
- Higher level branching on a schema version is never possible.
211+
- A specification's version must be bumped when a constituent trait has
212+
a version bump, even if nothing else in the specification has changed.
213+
Conceptually, specifications are trait version agnostic, but must
214+
become version-aware for the purposes of codegen, which is
215+
inconsistent.
216+
217+
## Outcome
218+
219+
We will implement Option 2 - Per Trait/Specification versioning.
220+
221+
A huge benefit is how much easier it is to make this solution a
222+
non-breaking change to current users.
223+
224+
In addition, it has better discoverability through IDE code completion,
225+
and it is easier to view history through a single YAML document rather
226+
than across several documents.
227+
228+
There will be a rather large change to the `traitgen` tool and the YAML
229+
JSON schema, causing a headache for any early adopters who are
230+
generating their own traits. However, this is less critical than changes
231+
to the generated output in use within pipelines.

0 commit comments

Comments
 (0)