fix: export serialization + load_some resilience (closes #4)#5
Merged
deucalioncodes merged 4 commits intomainfrom Mar 21, 2026
Merged
fix: export serialization + load_some resilience (closes #4)#5deucalioncodes merged 4 commits intomainfrom
deucalioncodes merged 4 commits intomainfrom
Conversation
…oses #4) - serialize(for_export=True) skips OneToMany relations (reconstructed from reverse ManyToOne) and serializes OneToOne only on one deterministic side (alphabetically-earlier entity type carries the reference). This prevents circular/dangling references in exported JSON. - load_some() now catches ValueError/AttributeError per entity, skipping broken entities with dangling relation refs instead of crashing the batch. - 8 new tests: 4 for for_export behavior + 4 issue #4 regression tests covering bidirectional OneToOne import, OneToMany dangling refs, export-eliminates-dangling, and full round-trip.
…y and picks one side of OneToOne Breaking change (no production use yet): serialize() now always produces clean output without OneToMany relations and with deterministic OneToOne side selection. This simplifies the API — callers no longer need to pass for_export=True. Updated all tests to match new default behavior.
…r persistence) serialize() skips OneToMany and picks one side of OneToOne — safe for export/import without circular refs. _serialize_full() preserves all relations — used by _save() so internal persistence (load/save cycles) keeps working correctly. _serialize_base() and _get_entity_reference() are shared helpers.
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
Fixes #4 — Robust JSON serialization/deserialization with lazy relation resolution.
Changes
serialize(for_export=True)— new parameter onEntity.serialize():OneToManyrelations (always reconstructed from reverseManyToOneduring import)OneToOneon one deterministic side only: the entity whose type name is alphabetically ≤ the target type carries the reference. This eliminates circular references in exported JSON.for_export=Falsepreserves full backward compatibility for internal storage.load_some()resilience:ValueError/AttributeErrorper entity during batch loadingTests
8 new tests in
test_serialization.py:test_serialize_for_export_skips_one_to_manytest_serialize_for_export_one_to_one_deterministictest_serialize_for_export_round_triptest_serialize_for_export_many_to_manytest_issue4_bidirectional_one_to_one_import_order— reproduces the exact User↔Member crashtest_issue4_one_to_many_dangling_refs_load_some— reproduces Token→WalletBalance crashtest_issue4_for_export_eliminates_dangling_one_to_many— proves export prevents danglingtest_issue4_full_round_trip_bidirectional— end-to-end Realm→User→Human→Member round-trip