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-190-2: Use ss v2 for labware metadata #1847

Merged
merged 25 commits into from
Aug 14, 2024

Conversation

sdjmchattie
Copy link
Contributor

Closes #1803

Changes proposed in this pull request

  • Change LabwareMetadata class to use V2 endpoints only.
  • Fix a spectacular number of tests that this breaks.

Instructions for Reviewers

[All PRs] - Confirm PR template filled
[Feature Branches] - Review code

Only just found out about it and it looks like it hasn't been done by anyone in recent times.
It's used by sub-classes so they need to be fixed first
…etadata

# Conflicts:
#	spec/models/labware_creators/pcr_cycles_binned_plate_for_t_nano_seq_spec.rb
This includes creating a new module which lets LabwareCreators lookup a V2 plate as a `source_plate` when they usually only deal with v1 plates as `parent`.
They no longer use the api V1 and the tests were passing them the api variable when they no longer accept one.
Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.55%. Comparing base (4fc7eeb) to head (1e1a076).
Report is 18 commits behind head on develop-Y24-190.

Files Patch % Lines
...ncerns/labware_creators/support_v2_source_plate.rb 85.71% 1 Missing ⚠️
app/models/labels/plate_split.rb 0.00% 1 Missing ⚠️
app/models/labware_creators/pooled_tubes_base.rb 75.00% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           develop-Y24-190    #1847      +/-   ##
===================================================
+ Coverage            91.48%   91.55%   +0.06%     
===================================================
  Files                  380      382       +2     
  Lines                 7738     7813      +75     
===================================================
+ Hits                  7079     7153      +74     
- Misses                 659      660       +1     
Flag Coverage Δ
javascript 94.01% <ø> (+0.33%) ⬆️
pull_request 91.49% <90.90%> (?)
push 91.48% <90.90%> (+<0.01%) ⬆️
ruby 91.19% <90.90%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@source_plate = nil
end

@source_plate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the instance variable at the bottom do? How does it work when you have both a function and instance variable with the same name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overriding the getter for the instance variable to fetch the plate using v2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pattern called memoization where you use the @ variable to store a cached value to avoid having to perform the lookup repeatedly for the parent UUID. Rubocop requires that you use the same name for the @ variable as you do for the method that populates it. See a blog article on memoization here: https://blog.appsignal.com/2022/12/20/a-guide-to-memoization-in-ruby.html

When you call self.source_plate from elsewhere in the class (and publically in this case), the method will be preferred over the @ variable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok cool, thanks I didn't realise you could do it this way. I think I've used a similar way before something like:

def source_plate
   @ source_plate ||= <method_call>
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what I'm doing here as well. It's just complicated by the fact that we have to check the type first before converting it and an if check to ensure we do over-write our memoized version if, somehow, the parent has changed.


stub_v2_user(user)

stub_v2_labware(stock_plate_v2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a nice way of handling this where we can give it a list of plates instead of invoking it for each plate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add more stub methods, but there are already a lot of them. We could use some sort of nasty reflection method where we tell it to stub resources and pass the type as a string, constantizing it to get a reference to the individual stub method and looping inside the stubs module. Or we could set this up something like:

[child_plate_a, child_plate_b, child_plate_c, child_plate_d, child_plate_e].each { |labware| stub_v2_labware(labware) }

But as these are tests, do not need to conform to DRY approaches, and I want the setup to be very clear to anyone who needs to understand what the setup and outcomes are, I don't think we should do any of that.

@@ -93,10 +96,10 @@ def metadata_stock_barcode
end

def parent_metadata
if parent.is_a? Limber::Plate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the concept of a plate meant to be used in Limber and one only meant to be used in Sequencescape. You get a warning in the GUI if you scan a non-Limber plate in Limber.
Is this Limber::Plate check to do with that? And why do you replace it here but then use it in the support_v2_plate_source_plate code above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the method source_plate is badly named. I took that from code James Glover wrote for cardinal pools plate labware creator to convert a parent into a V2 plate. Not all the labware creators deal with plates I believe since one of the tests fails if I don't check that we have a plate here. In which case it falls back to passing the parent's barcode to the LabwareMetadata. I guess when it's a tube, as it is in one of the tests, it gives the barcode of the tube to LabwareMetadata and the labware gets looked up that way. I don't know if there are any real life instances where the labware would not be able to be looked up by its barcode. I assumed so because of the dual functionality constructor that can take the labware itself or the barcode. But perhaps that's legacy functionality and we could make our lives a lot easier by only using the barcodes all the time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've change this now to be cleaner.

Either it's the correct type, or it's nil, which is when we would fall back to the barcode instead for LabwareMetadata
@sdjmchattie sdjmchattie merged commit 64aa80f into develop-Y24-190 Aug 14, 2024
11 of 12 checks passed
@sdjmchattie sdjmchattie deleted the Y24-190-2-use-ss-v2-for-labware-metadata branch August 14, 2024 08:56
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

Successfully merging this pull request may close these issues.

3 participants