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

Y24-225 - [BUG] LabWhere location child count not updating correctly #813

Closed
3 tasks
neilsycamore opened this issue Jul 29, 2024 · 2 comments · Fixed by #819
Closed
3 tasks

Y24-225 - [BUG] LabWhere location child count not updating correctly #813

neilsycamore opened this issue Jul 29, 2024 · 2 comments · Fixed by #819
Assignees
Labels
Bug Something isn't working

Comments

@neilsycamore
Copy link

There are 129 location instances where the child count is incorrect
Location.all.filter { |l| l.children_count != l.children.count }.count
LabWhere is displaying the location's child_count attribute but this is not being updated from location.child.count
Screenshot 2024-07-29 at 14 47 01
Above shows that location Sanger / Sulston / B105 has 9 children where it actually has 8

Acceptance criteria:

  • fix bug (@BenTopping not sure what the bug is??)
  • The incorrect instances are updated
  • Location.all.filter { |l| l.children_count != l.children.count }.count == 0
    Contacts
    nts, bt8
@neilsycamore neilsycamore added the Bug Something isn't working label Jul 29, 2024
@psd-issuer psd-issuer bot changed the title [BUG] LabWhere location child count not updating correctly Y24-225 - [BUG] LabWhere location child count not updating correctly Jul 29, 2024
@BenTopping
Copy link
Contributor

BenTopping commented Jul 29, 2024

Initial research suggests thats Location child_children count is not always in sync with the actual children count. This children_count column is controlled by a gem https://github.com/stefankroes/ancestry so its behaviour is obfuscated but its reference can be seen in the Location model.

It could be as simple as writing a script to sync up the count but there is a concern as to why it is out of sync. Im not really sure this gem is needed as it doesn't really make sense to store children_count in the db when we can work it out dynamically with higher accuracy. My only thought would be its stored for performance reasons but I don't know if thats the only trade off with removing it?

@seenanair seenanair self-assigned this Aug 19, 2024
@seenanair
Copy link
Contributor

seenanair commented Aug 21, 2024

Findings:

The children_count column is stored in the database for performance reasons, rather than being calculated dynamically. Initially, we managed the hierarchy manually, but this was later replaced by the Ancestry gem (possibly for performance reasons). The issue seems to be that the children_count column is managed by the Ancestry gem, but the gem is not updating it correctly in certain actions. Despite testing various actions like removing, adding, and moving labware/locations between parents, we have been unable to consistently reproduce the specific scenario where this issue occurs.

The assumption is that something might be interfering with the Ancestry gem’s callbacks, potentially custom callbacks (e.g., before_save, after_create, etc.) in the Location model. Since a specific action causing this bug cannot be identified, understanding the root cause has been difficult.

This is a known issue which is raised in ancestry repo stefankroes/ancestry#584 and the suggested solution is to to use rebuild_counter_cache stefankroes/ancestry#663.
But, this is not yet released.

Currently a rake task is created to fix all out of sync children_count to correct values.

P.S.: Labwhere logs have been checked for errors related to the Ancestry gem, but none were found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants