Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
valhuber opened this issue Mar 1, 2022 · 0 comments
Open
Assignees

Comments

@valhuber
Copy link
Owner

valhuber commented Mar 1, 2022

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.

@valhuber valhuber self-assigned this Mar 1, 2022
@valhuber valhuber changed the title Allocation Fails in Api Logic Server Allocation Fails in Api Logic Server - reports missing relationship Mar 2, 2022
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

No branches or pull requests

1 participant