Skip to content

fix(org): Cyclic dep check bug fix

Andrii Bezuglyi requested to merge fix/org_cyclic_dep_check into master

Cyclic dep check contains the following query:

const store = UB.Repository('org_unit').attrs(['ID', 'parentID', 'mi_treePath'])
    .where('[parentID]', '=', parentID).select()

It does not look good:

  • we are querying all children of the new parent, while we should only query the new parent itself!
  • the subsequent code does not loop the store, it only interested in the first result row, which proves that author intention was to check one row - new parent

The current code almost in any case work - it queries all children of new parent, use a random first of them for check. The only problem occurs, when client pass unchanged parentID along with execParams, which is kind of legal situation, for example import/migration scripts, which do not do client-side comparison "before"/"after". In such a case, the ID of the record itself is present in mi_treePath and it causes false alarm about cyclic dependencies, and "update" call fails.

Fix is trivial - just query the parent record, not full set of children.

Edited by Andrii Bezuglyi

Merge request reports

Loading