Skip to content

Commit

Permalink
0.9.4 - show session, fix Parent Missing warning
Browse files Browse the repository at this point in the history
  • Loading branch information
valhuber committed Feb 21, 2021
1 parent 74a8927 commit b58325e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ additional parameters
0.9.0 - Add logicRow.get_derived_attributes, which
can be used to enforce behaviors such as
`Unalterable Derivations <https://github.com/valhuber/LogicBank/wiki/Rule-Extensibility#unalterable-derivations>`_

0.9.2 - Add session to logic_row.__str__(), listeners

0.9.3 - Allow for nulls in summed/sum

0.9.4 - Fix bad Warning: Missing Parent:
10 changes: 6 additions & 4 deletions logic_bank/exec_row_logic/logic_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ def __str__(self):
result += value
else:
result += str(value)
result += f' row@: {str(hex(id(self.row)))}'
result += f' session@: {str(hex(id(self.session)))}'
result += f' row: {str(hex(id(self.row)))}'
result += f' session: {str(hex(id(self.session)))}'
return result # str(my_dict)

def log(self, msg: str) -> str:
Expand Down Expand Up @@ -665,10 +665,12 @@ def load_parents_on_insert(self):
if each_relationship.direction == sqlalchemy.orm.interfaces.MANYTOONE: # cust, emp
parent_role_name = each_relationship.key # eg, OrderList
if self.is_foreign_key_null(each_relationship) is False:
# continue
# continue - foreign key not null - parent *should* exist
self.get_parent_logic_row(parent_role_name) # sets the accessor
does_parent_exist = getattr(self.row, parent_role_name)
if does_parent_exist is None and ref_integ_enabled:
if does_parent_exist:
pass # yes, parent exists... it's all fine
elif ref_integ_enabled:
msg = "Missing Parent: " + parent_role_name
self.log(msg)
ll = RuleBank()
Expand Down
8 changes: 4 additions & 4 deletions logic_bank/exec_trans_logic/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def before_commit(a_session: session):
* not called for auto-commit transactions
* called prior to before_flush
"""
logic_bank.logic_logger.debug("\nLogic Phase:\t\tBEFORE COMMIT \t\t\t\t\t\t")
logic_bank.logic_logger.debug(f'\nLogic Phase:\t\tBEFORE COMMIT(session={str(hex(id(a_session)))}) \t\t\t\t\t\t')


def before_flush(a_session: session, a_flush_context, an_instances):
Expand All @@ -29,7 +29,7 @@ def before_flush(a_session: session, a_flush_context, an_instances):
"""
Logic Phase
"""
logic_bank.logic_logger.debug("Logic Phase:\t\tROW LOGIC (sqlalchemy before_flush)\t\t\t")
logic_bank.logic_logger.debug(f'Logic Phase:\t\tROW LOGIC(session={str(hex(id(a_session)))}) (sqlalchemy before_flush)\t\t\t')

row_sets = RowSets() # type : RowSet
client_inserts = []
Expand Down Expand Up @@ -71,7 +71,7 @@ def before_flush(a_session: session, a_flush_context, an_instances):
"""
Commit Logic Phase
"""
logic_bank.logic_logger.debug("Logic Phase:\t\tCOMMIT \t\t\t\t\t\t\t\t\t")
logic_bank.logic_logger.debug(f'Logic Phase:\t\tCOMMIT(session={str(hex(id(a_session)))}) \t\t\t\t\t\t\t\t\t\t')
processed_rows = dict.copy(row_sets.processed_rows) # set in LogicRow ctor
for each_logic_row_key in processed_rows:
each_logic_row = processed_rows[each_logic_row_key]
Expand All @@ -84,7 +84,7 @@ def before_flush(a_session: session, a_flush_context, an_instances):
"""
Proceed with sqlalchemy flush processing
"""
logic_bank.logic_logger.debug("Logic Phase:\t\tFLUSH (sqlalchemy flush processing \t")
logic_bank.logic_logger.debug(f'Logic Phase:\t\tFLUSH(session={str(hex(id(a_session)))}) (sqlalchemy flush processing) \t')


def temp_debug(a_session, bug_explore, row_cache):
Expand Down
3 changes: 3 additions & 0 deletions logic_bank/extensions/copy_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def execute(self, logic_row: LogicRow):
copy_to_logic_row = copy_from.new_logic_row(new_row_class=self.copy_to)
copy_to_logic_row.link(to_parent=copy_from)
copy_to_logic_row.set_same_named_attributes(copy_from)
do_session_add = False
if do_session_add: # does not appear to matter...
copy_to_logic_row.session.add(copy_to_logic_row.row)
copy_to_logic_row.insert(reason="Copy " + copy_to_logic_row.name) # triggers rules...
# copy_from.log(f'END {str(self)}')
return self
2 changes: 2 additions & 0 deletions logic_bank/rule_type/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def adjust_from_inserted_child(self,
curr_value = getattr(parent_adjustor.parent_logic_row.row, self._column)
if curr_value is None:
curr_value = 0
if delta is None:
delta = 0
setattr(parent_adjustor.parent_logic_row.row, self._column, curr_value + delta)
# parent_adjustor.child_logic_row.log(f'adjust_from_inserted/adopted_child adjusts {str(self)}')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def desc():

setup(
name="logicbank",
version="0.9.0",
version="0.9.4",
url="https://github.com/valhuber/logicbank",
license="BSD",
author="Val Huber",
Expand Down

0 comments on commit b58325e

Please sign in to comment.