feat: Add registered-type JSON pipeline for Durable Functions custom objects#336
Open
andystaples wants to merge 2 commits intoAzure:devfrom
Open
feat: Add registered-type JSON pipeline for Durable Functions custom objects#336andystaples wants to merge 2 commits intoAzure:devfrom
andystaples wants to merge 2 commits intoAzure:devfrom
Conversation
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors
azure.functions._durable_functionsto introduce an explicit registry for round-tripping user-defined classes through JSON, and reworks the existing_serialize_custom_object/_deserialize_custom_objecthelpers so that decoding is a pure data transformation (no module loading, no I/O).What changed
azure.functions._durable_functions:register_durable_serializable_type(cls)— opt-in registration (usable as a decorator) for classes that exposeto_json/from_json.to_json_string(obj)/from_json_string(s, *, accept_legacy=False)— symmetric encode/decode pipeline. Plain JSON values round-trip unchanged; dicts whose shape would collide with an internal marker are escaped on encode and restored on decode; only registered classes are reconstructed from__azfunc_obj__markers._serialize_custom_objectstill emits the legacy__class__/__module__/__data__shape, but now requires the class to be registered._deserialize_custom_objectresolves target classes through the registry first, falling back to a hardened lookup in already-loaded modules (sys.modulesonly). The fallback requires a realtypein the named module that definesto_jsonand aclassmethod/staticmethodfrom_json. Unrecognised markers pass through as plain dicts.AZURE_FUNCTIONS_DURABLE_STRICT_LEGACY_DESERIALIZEenv flag disables thesys.modulesfallback for callers who want registry-only resolution.DeprecationWarning(resolved or not) so callers can migrate to the registry; the legacy shape will be removed in the next major.OrchestrationContextandEntityContextare unchanged.Tests
tests/test_durable_functions.pygains coverage for:_NoLazyImportscontext manager that asserts decode never callsimportlib.import_moduleacross every entry point and input shape,from_json, missingto_json, non-class attribute, re-export with mismatched__module__),accept_legacy=True, including registry precedence,sys.modulesfallback, strict mode, unloaded module, and theaccept_legacy=Falsedefault,import_modulebinding).Compatibility
from_json_string(..., accept_legacy=True).DeprecationWarninginvites them to callregister_durable_serializable_type(cls).dict(with a warning that explains how to opt in via the registry or by importing at startup).