Skip to content

Implement self ref fk ordering#322

Merged
rtibbles merged 12 commits into
learningequality:release-v0.9.xfrom
ozer550:implement-self-ref-fk-ordering
Jun 3, 2026
Merged

Implement self ref fk ordering#322
rtibbles merged 12 commits into
learningequality:release-v0.9.xfrom
ozer550:implement-self-ref-fk-ordering

Conversation

@ozer550
Copy link
Copy Markdown
Contributor

@ozer550 ozer550 commented Apr 29, 2026

Summary

Introduce deterministic ordering support for self-referential foreign key (FK) models during sync by adding a _self_ref_order field to Morango store records, allowing store/buffer rows to be processed parent-before-child in a streaming-friendly way. Adds a morango_ordering hook for syncable models so Morango can order querysets consistently (with nulls last), and adds a SELF_REF_ORDER capability to negotiate support between peers and preserve backwards compatibility.

TODO

  • Have tests been written for the new code?
  • Has documentation been written/updated?
  • New dependencies (if any) added to requirements file

Reviewer guidance

If you PR has a significant size, give the reviewer some helpful remarks

Issues addressed

closes #297

Documentation

If the PR has documentation, link the file here (either .rst in your repo or if built on Read The Docs)

@ozer550 ozer550 requested a review from bjester April 29, 2026 15:09
Comment thread morango/sync/stream/serialize.py Outdated
Comment thread morango/sync/stream/serialize.py
@ozer550 ozer550 force-pushed the implement-self-ref-fk-ordering branch from 59d644d to aff0bbc Compare May 6, 2026 10:08
@ozer550 ozer550 marked this pull request as ready for review May 6, 2026 10:08
@ozer550 ozer550 requested a review from bjester May 6, 2026 10:08
@bjester bjester self-assigned this May 19, 2026
@bjester bjester force-pushed the implement-self-ref-fk-ordering branch from aff0bbc to 22635f3 Compare June 2, 2026 16:43
@bjester bjester force-pushed the implement-self-ref-fk-ordering branch from 22635f3 to b19197b Compare June 2, 2026 17:00
@rtibbles rtibbles self-assigned this Jun 2, 2026
)

parent = Store.objects.filter(
id=Cast(OuterRef("_self_ref_fk"), UUIDField()),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the Cast here, as postgres complained about a mismatch in type.

Copy link
Copy Markdown
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve of @ozer550's changes!

As for my changes, I resolved merge conflicts, fixed a postgres error, ensured our buffered chunks are always partitioned by model, and did some refactoring for partitioned buffers and self-ref FK lookups.

Copy link
Copy Markdown
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concerns from a read through, and the implementation matches the spec to my eyes. No obvious artifacts from the merge conflict resolution.

@rtibbles rtibbles merged commit d3d3a28 into learningequality:release-v0.9.x Jun 3, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Self-Referential FK Order

3 participants