Migrate domain models does not set subscription_instance_relations.domain_model_attr
https://github.com/workfloworchestrator/orchestrator-core/blob/271ac32d2e122034bb71aedce402495fcc766843/orchestrator/cli/domain_gen_helpers/product_block_helpers.py#L204
After adding a new product block, the migrate-domain-models command can be used to compare domain models to the database and generate migrations to bring the database in sync.
One of these migrations creates subscription_instance_relations records to relate existing subscription instances to the new subscription instances. However, the generated migrations currently don't set the domain_model_attr column. For example, the SQL query looks like this:
INSERT INTO subscription_instance_relations (in_use_by_id, depends_on_id, order_id)
VALUES (
'0c40000c-3e70-42cd-a6ab-2008468fd4eb',
(SELECT subscription_instances.subscription_instance_id FROM subscription_instances WHERE subscription_instances.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('test block')) AND subscription_instances.subscription_id = '019db62f-1d8c-499e-b172-048c1f9ed126' LIMIT 1),
0
)
This is automatically corrected by the next time SubscriptionModel.save() is called (e.g. during a validation) in which fills the domain_model_attr. But until that save has been run, the database is not in sync. Moreover, when a product block refers to another product block more than once in different fields, then this cannot be reliably loaded deserialized by the domain model. For example:
class ProductBlock1(ProductBlockModel):
pb2_a: ProductBlock2
pb2_b: ProductBlock2
The solution is to change the generator so that the aforementioned generated sql query specify the domain model attr:
INSERT INTO subscription_instance_relations (in_use_by_id, depends_on_id, order_id, domain_model_attr)
VALUES (
'0c40000c-3e70-42cd-a6ab-2008468fd4eb',
(SELECT subscription_instances.subscription_instance_id FROM subscription_instances WHERE subscription_instances.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('test block')) AND subscription_instances.subscription_id = '019db62f-1d8c-499e-b172-048c1f9ed126' LIMIT 1),
0,
'pb2_a'
)
The testcase test.unit_tests.cli.test_migrate_domain_models_with_instances.test_migrate_domain_models_new_product_block_on_product_block can be used to reproduce and test this, and should no longer be an XFAIL afterwards