Skip to content

Repair Tree function doesn't work #2776

@grantfitzsimmons

Description

@grantfitzsimmons

Say you have a database where the found {not_nested_count} nodenumbers not nested by parent error is taking place– the 'Repair Tree' button will be unable to solve this. It does not renumber the tree despite claiming to...

def validate_tree_numbering(table):
logger.info('validating tree')
cursor = connection.cursor()
cursor.execute(
"select count(*), count(distinct nodenumber), count(highestchildnodenumber)\n"
"from {table}".format(table=table)
)
node_count, nn_count, hcnn_count = cursor.fetchone()
assert node_count == nn_count == hcnn_count, \
"found {} nodes but {} nodenumbers and {} highestchildnodenumbers" \
.format(node_count, nn_count, hcnn_count)
cursor.execute((
"select count(*) from {table} t join {table} p on t.parentid = p.{table}id\n"
"where t.rankid <= p.rankid\n"
"and t.acceptedid is null"
).format(table=table))
bad_ranks_count, = cursor.fetchone()
assert bad_ranks_count == 0, \
"found {} cases where node rank is not greater than its parent." \
.format(bad_ranks_count)
cursor.execute((
"select count(*) from {table} t join {table} p on t.parentid = p.{table}id\n"
"where t.nodenumber not between p.nodenumber and p.highestchildnodenumber\n"
).format(table=table))
not_nested_count, = cursor.fetchone()
assert not_nested_count == 0, \
f"found {not_nested_count} nodenumbers not nested by parent"

Metadata

Metadata

Assignees

No one assigned

    Labels

    1 - BugIncorrect behavior of the product2 - TreesIssues that are related to the tree system and related functionalities.

    Type

    No type

    Projects

    Status

    📋 Backlog

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions