@@ -58,10 +58,10 @@ def test_io_dicts_excludes_implicit_output_collections():
5858 assert "paired_output" in io .out_collections
5959
6060
61- def test_implicit_collection_jobs_serialize_skips_orphan_associations ():
62- """ImplicitCollectionJobsJobAssociation.job_id is nullable; orphan rows
63- (e.g. produced by partial imports) must be skipped on export instead of
64- crashing in SerializationOptions.get_identifier on a None job ."""
61+ def test_implicit_collection_jobs_serialize_orphan_associations ():
62+ """ImplicitCollectionJobsJobAssociation.job_id is nullable; orphan rows can
63+ be persisted by the import path. Strict mode (default) lets the crash
64+ propagate; tolerate_missing_data mode skips the orphan ."""
6565 icj = model .ImplicitCollectionJobs ()
6666 job = model .Job ()
6767 job .id = 42
@@ -73,15 +73,31 @@ def test_implicit_collection_jobs_serialize_skips_orphan_associations():
7373 orphan .order_index = 1 # job left as None
7474 icj .jobs = [linked , orphan ]
7575
76- rval = icj ._serialize (id_encoder = None , serialization_options = model .SerializationOptions (for_edit = True ))
76+ strict = model .SerializationOptions (for_edit = True )
77+ try :
78+ icj ._serialize (id_encoder = None , serialization_options = strict )
79+ except AttributeError :
80+ pass
81+ else :
82+ raise AssertionError ("strict mode should have raised on orphan ICJJA" )
83+
84+ tolerant = model .SerializationOptions (for_edit = True , tolerate_missing_data = True )
85+ rval = icj ._serialize (id_encoder = None , serialization_options = tolerant )
7786 assert rval ["jobs" ] == [42 ]
7887
7988
80- def test_job_serialize_passes_through_null_param_ids ():
81- """Job params can contain {"src": "hda"|"hdca"|"dce", "id": null} references
82- (e.g. from corrupted state); export must pass null ids through instead of
83- raising NotImplementedError in get_identifier_for_id."""
84- options = model .SerializationOptions (for_edit = True )
85- assert options .get_identifier_for_id (id_encoder = None , obj_id = None ) is None
86- assert options .get_identifier_for_id (id_encoder = None , obj_id = 0 ) == 0
87- assert options .get_identifier_for_id (id_encoder = None , obj_id = 42 ) == 42
89+ def test_get_identifier_for_id_null_handling ():
90+ """Null job-param ids raise in strict mode and pass through in
91+ tolerate_missing_data mode."""
92+ strict = model .SerializationOptions (for_edit = True )
93+ try :
94+ strict .get_identifier_for_id (id_encoder = None , obj_id = None )
95+ except NotImplementedError :
96+ pass
97+ else :
98+ raise AssertionError ("strict mode should have raised on null obj_id" )
99+
100+ tolerant = model .SerializationOptions (for_edit = True , tolerate_missing_data = True )
101+ assert tolerant .get_identifier_for_id (id_encoder = None , obj_id = None ) is None
102+ assert tolerant .get_identifier_for_id (id_encoder = None , obj_id = 0 ) == 0
103+ assert tolerant .get_identifier_for_id (id_encoder = None , obj_id = 42 ) == 42
0 commit comments