Skip to content

Allocation Fails in Api Logic Server - reports missing relationship #6

@valhuber

Description

@valhuber

See the Allocation sample.

Throws: Data error Missing relationship from Parent Provider: <Payment> to child Allocation: <class 'database.models.PaymentAllocation'> of class: PaymentAllocation.

Root cause is in LogicRow:

    def link(self, to_parent: 'LogicRow'):
        """
        set self.to_parent (parent_accessor) = to_parent

        Example
            if logic_row.are_attributes_changed([Employee.Salary, Employee.Title]):
                copy_to_logic_row = logic_row.new_logic_row(EmployeeAudit)
                copy_to_logic_row.link(to_parent=logic_row)  # link to parent Employee
                copy_to_logic_row.set_same_named_attributes(logic_row)
                copy_to_logic_row.insert(reason="Manual Copy " + copy_to_logic_row.name)  # triggers rules...

        Args:
            to_parent: mapped class that is parent to this logic_row

        """
        parent_mapper = object_mapper(to_parent.row)
        parents_relationships = parent_mapper.relationships
        parent_role_name = None
        child = self.row
        for each_relationship in parents_relationships:  # eg, Payment has child PaymentAllocation
            if each_relationship.direction == sqlalchemy.orm.interfaces.ONETOMANY:  # PA
                each_parent_role_name = each_relationship.back_populates  # eg, PaymentAllocationList
                child_row_class_name = str(child.__class__.__name__)  # eg, PaymentAllocation
                child_reln_class_name = str(each_relationship.entity.class_.__name__)  # eg., PaymentAllocation
                # if child_row_class_name == child_reln_class_name:  FIX..
                if isinstance(child, each_relationship.entity.class_):
                    if parent_role_name is not None:
                        raise Exception("TODO - disambiguate relationship from Provider: <" +
                                        to_parent.name +
                                        "> to Allocation: " + str(type(child)))
                    parent_role_name = parent_mapper.class_.__name__ 
        if parent_role_name is None:
            raise Exception("Missing relationship from Parent Provider: <"  +
                            to_parent.name +
                            "> to child Allocation: " + str(type(child)) + " of class: " + child.__class__.__name__)

isInstance fails due to packed name in SQLAlchemy meta data expecting a nodal name.

Fix: LogicBank==1.4.3

Replacing isInstance fixes this bug.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions