skrawcz commented on PR #931:
URL: https://github.com/apache/burr/pull/931#issuecomment-6115980749
Some concrete approaches that could satisfy the serde integration request:
### 1. Serialization context passed through existing serde APIs
Introduce an application-scoped context supplied to `State.serialize()` /
`State.deserialize()` and therefore to both type-based and field-name-based
serializers. For example, the context could expose `object_store` plus any
future serialization services:
```python
def serialize_pdf(value, *, serialization_context, **kwargs):
ref = serialization_context.object_store.put_artifact(value.to_bytes())
return serialize_artifact_ref(ref)
```
The important part is that Burr—not each user—must propagate the same
context through every serialization path: state persisters, trackers,
initialization/resume, and sub-applications. This avoids capturing an
application-specific store in the global serde registry or manually duplicating
`serde_kwargs` across components.
For async stores, this likely requires corresponding `State.aserialize()` /
`State.adeserialize()` support and async serializer registration; calling an
async store from the current synchronous serializer contract would otherwise
block or be impossible to await correctly.
### 2. First-class artifact-backed field/type registration
Add a higher-level API over serde, along the lines of:
```python
register_artifact_field(
"pdf",
encode=lambda pdf: pdf.to_bytes(),
decode=PDF.from_bytes,
media_type="application/pdf",
load="lazy",
)
```
There could be an equivalent type-based registration. Burr would encode and
store the value, persist an `ArtifactRef`, and restore either the reference or
a lazy wrapper that knows how to materialize through the configured store. This
is more ergonomic and lets Burr define consistent lazy-loading and sync/async
behavior, but it is a larger API commitment.
### 3. Externalization lifecycle adapter
A pre-persistence sync/async adapter could replace configured large fields
with references before trackers and persisters serialize state. This is
probably the smallest implementation, and an async adapter can await uploads,
but it has drawbacks: ordering among lifecycle adapters becomes
correctness-sensitive, and it may mutate the live shape/type of state unless
paired with a lazy wrapper. I would be cautious about making this the primary
public model.
My preference is **(1) as the foundational contract**, optionally followed
by **(2) as the ergonomic API**. A serialization context composes with Burr's
existing type- and field-level serde mechanisms instead of replacing them,
while explicit async serialization keeps async Python first-class. The
higher-level artifact registration can then be implemented cleanly on top.
Whichever route we choose, I think tests should cover both type- and
field-name registration across persistence + reload, tracking serialization,
sub-applications, and sync/async stores.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]