From 3526c43a28974d848554332728f1b0f19c8f51c6 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Wed, 14 Oct 2026 08:31:25 +0530 Subject: [PATCH] fix(seed_content): preserve source document authoring order for module contents sort order --- app/bootstrap/seed_content/modules.py | 11 ++++++++++- app/bootstrap/seed_content/orchestrator.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/bootstrap/seed_content/modules.py b/app/bootstrap/seed_content/modules.py index 23ed6c8..7c9b947 100644 --- a/app/bootstrap/seed_content/modules.py +++ b/app/bootstrap/seed_content/modules.py @@ -121,8 +121,17 @@ class ModuleSeeder: from {self._schema}.content_items ci join {self._schema}.attribute_definition_sets ads on ads.id = ci.attribute_definition_set_id + left join {self._schema}.content_attributes ca + on ca.content_id = ci.id + and ca.attribute_definition_id = ( + select id + from {self._schema}.attribute_definitions + where attribute_definition_set_id = ads.id + and code = 'sort_order' + limit 1 + ) where ads.code = :definition_set_code - order by ci.sort_title asc, ci.id asc + order by ca.value_number asc nulls last, ci.sort_title asc, ci.id asc """), {"definition_set_code": definition_set_code}, ) diff --git a/app/bootstrap/seed_content/orchestrator.py b/app/bootstrap/seed_content/orchestrator.py index 240ee1c..e43ff3f 100644 --- a/app/bootstrap/seed_content/orchestrator.py +++ b/app/bootstrap/seed_content/orchestrator.py @@ -300,6 +300,16 @@ class SeedOrchestrator: # seeded by this invocation are candidates for module # association. Never rewrite unrelated template rows. content_ids = [result.content_id for result in batch.results] + elif batch.results: + # Preserve authored sequence from the source document. + content_ids = [result.content_id for result in batch.results] + known_ids = set(content_ids) + all_ids = await self._modules.resolve_content_ids_for_definition_set( + definition_set_code=mapping.code + ) + for remaining_id in all_ids: + if remaining_id not in known_ids: + content_ids.append(remaining_id) else: content_ids = await self._modules.resolve_content_ids_for_definition_set( definition_set_code=mapping.code