diff --git a/snowfakery/row_history.py b/snowfakery/row_history.py index 1d53b284..7650b9c0 100644 --- a/snowfakery/row_history.py +++ b/snowfakery/row_history.py @@ -6,7 +6,7 @@ from random import randint from snowfakery import data_gen_exceptions as exc -from snowfakery.object_rows import LazyLoadedObjectReference +from snowfakery.object_rows import LazyLoadedObjectReference, ObjectRow from snowfakery.utils.pickle import RestrictedPickler from snowfakery.object_rows import NicknameSlot, ObjectReference @@ -167,7 +167,11 @@ def _make_history_table(conn, tablename): NicknameSlot: lambda n: ( ObjectReference, (n._tablename, n.allocated_id), - ) + ), + ObjectRow: lambda v: ( + ObjectRow, + (v._tablename, v._values), + ), } _SAFE_CLASSES = { diff --git a/tests/test_references.py b/tests/test_references.py index 997bad05..f680eafd 100644 --- a/tests/test_references.py +++ b/tests/test_references.py @@ -913,32 +913,56 @@ def test_random_reference_to_objects_with_diverse_types(self, generated_rows): assert parse_date(generated_rows.table_values("B", 1, "datetime1ref")) assert parse_date(generated_rows.table_values("B", 1, "datetime2ref")) - # TODO: Make this work - # def test_random_references__nested_1(self, generate_data_with_continuation, generated_rows): - # yaml = """ - # - object: Parent - # count: 2 - # fields: - # child1: - # - object: Child1 - # fields: - # child2: - # - object: Child2 - # fields: - # name: TheName - # - object: Child3 - # fields: - # A_ref: - # random_reference: - # to: Parent - # nested_name: - # ${{A_ref.child1.child2.name}} - # """ - # generate(StringIO(yaml)) - # # generate_data_with_continuation( - # # yaml=yaml, - # # target_number=("Parent", 4), - # # times=1, - # # ) - # assert generated_rows.table_values("Child3", 1, "nested_name") == "TheName" - # assert generated_rows.table_values("Child3", -1, "nested_name") == "TheName" + def test_random_references__nested(self, generated_rows): + yaml = """ + - object: Parent + count: 2 + fields: + child1: + - object: Child1 + fields: + child2: + - object: Child2 + fields: + name: TheName + - object: Child3 + fields: + A_ref: + random_reference: + to: Parent + nested_name: + ${{A_ref.child1.child2.name}} + """ + generate(StringIO(yaml)) + assert generated_rows.table_values("Child3", 1, "nested_name") == "TheName" + assert generated_rows.table_values("Child3", -1, "nested_name") == "TheName" + + def test_random_references__nested__with_continuation( + self, generate_data_with_continuation, generated_rows + ): + yaml = """ + - object: Parent + count: 2 + fields: + child1: + - object: Child1 + fields: + child2: + - object: Child2 + fields: + name: TheName + - object: Child3 + fields: + A_ref: + random_reference: + to: Parent + nested_name: + ${{A_ref.child1.child2.name}} + """ + generate_data_with_continuation( + yaml=yaml, + target_number=("Parent", 4), + times=1, + ) + assert generated_rows.table_values("Child3", 1, "nested_name") == "TheName" + assert generated_rows.table_values("Child3", -1, "nested_name") == "TheName"