[SYNPY-1795] JSONSchema now saves version info when storing - #1463
Merged
Merged
Conversation
BryanFauble
approved these changes
Oct 1, 2026
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.
Problem:
JSONSchema.store()returnsself, but it does not give the version data that Synapse makes during the store (semantic_version,version_id,created_on,created_by). Users cannot get this data from the returned object.(https://sagebionetworks.jira.com/wiki/spaces/DPE/pages/4576444437/Improving+JSONSchema.store+method+output).dry_run=True, Synapse makes the version, puts it in the response, and then deletes it.store_async()still setorganization_id,created_byandcreated_onfrom this deleted version.store_async()setcreated_onandcreated_byfrom the new version. OnJSONSchema, these fields describe the schema, not the version.store_async()set onlyorganization_id. It did not setidoruri. If a user callsget(), changesorganization_name, and then callsstore(), the object hasorganization_idfrom the new schema, butidandurifrom the old schema.JSONSchemaVersionInfo.json_schema_urireturned"<org>-<name>-None"when the version has no semantic version.Solution:
synapseclient/models/organization.py:JSONSchema.last_stored_version_info: Optional[JSONSchemaVersionInfo] = field(default=None, init=False, compare=False). Onlystore_async()sets it. It holds the version from the most recent store on this instance. It is not guaranteed to be the latest version in Synapse, andget()does not set or clear it.store_async()returns before any instance change whendry_run=True.store_async()setsorganization_id,id,uriandlast_stored_version_info. It does not setcreated_onorcreated_by.Attributes:,store_async()(with a new example), and the syncstore()onJSONSchemaProtocol.JSONSchema.organization_idannotation changed fromOptional[int]toOptional[str], as in the REST spec. The runtime behavior does not change.synapseclient/models/mixins/json_schema.py:JSONSchemaVersionInfo.semantic_versionchanged toOptional[str].json_schema_uridoes not add the-Nonesuffix whensemantic_versionis None.synapseclient/models/mixins/__init__.py: exportJSONSchemaVersionInfo.docs/reference/experimental/mixins/base_json_schema.md: addJSONSchemaVersionInfo.synapseclient/extensions/curator/schema_management.py: both examples now printjson_schema.last_stored_version_info.semantic_version.Example:
Testing:
Unit tests (
tests/unit/synapseclient/models/async/unit_test_organization_async.py): 59 pass.test_store_async_with_schema_body,test_store_async_with_version,test_get_async(asserts thatget_async()does not changelast_stored_version_info).test_store_async_dry_run(new schema, and schema filled from get with a priorlast_stored_version_info). It comparesdataclasses.asdict(schema)before and after the dry run.test_last_stored_version_info_field_definition(default is None,init=False,compare=False),test_store_async_after_get_updates_identity_keeps_created_values,test_store_async_second_store_replaces_version_info,TestJSONSchemaVersionInfo.test_json_schema_uri.Integration tests (
tests/integration/synapseclient/models/async/test_organization_async.py): all pass.test_store_and_get(now stores withversion="0.0.1"),test_delete_version(checkssemantic_versionis"0.0.1"and then"0.0.2").test_store_dry_run(the instance does not change, andget_versions_async()finds no versions).Integration tests (
tests/integration/synapseclient/operations/async/test_factory_operations_store_async.py):test_store_async_json_schema_basic. It asserted thatcreated_onis set after a store, andstore_async()does not set it now. It now checksid,last_stored_version_info, and thatsemantic_versionis"1.0.0".