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

fix(shared-data): find latest definition if version not specified #17223

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

caila-marashaj
Copy link
Contributor

Overview

When grabbing a labware definition, if a version is not specified, we default the file version to 1.json and check whether that file exists. This was done under the impression that all labware definitions in schema 3 would start at 1.json, but since that isn't the case, if no version is specified, we should just find the latest available labware def version that exists and load that.

@caila-marashaj caila-marashaj requested a review from a team as a code owner January 8, 2025 20:29
@caila-marashaj caila-marashaj force-pushed the load-newest-available-labware-def branch from a275f47 to e3345df Compare January 8, 2025 20:57
@caila-marashaj caila-marashaj force-pushed the load-newest-available-labware-def branch from e3345df to 884f185 Compare January 8, 2025 20:58
Copy link
Contributor

@ryanthecoder ryanthecoder left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@TamarZanzouri TamarZanzouri left a comment

Choose a reason for hiding this comment

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

LGTM!

@caila-marashaj caila-marashaj merged commit 89d6a3b into edge Jan 8, 2025
24 checks passed
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.04%. Comparing base (9a28d32) to head (884f185).
Report is 20 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #17223      +/-   ##
==========================================
+ Coverage   73.84%   79.04%   +5.20%     
==========================================
  Files          43      120      +77     
  Lines        3303     4586    +1283     
==========================================
+ Hits         2439     3625    +1186     
- Misses        864      961      +97     
Flag Coverage Δ
g-code-testing 92.43% <ø> (?)

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

see 77 files with indirect coverage changes

Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

Sorry I'm late for the review here. I'm not sure about these changes.

schema_3_dir = get_shared_data_root() / STANDARD_DEFS_PATH / "3" / load_name
if schema_3_dir.exists():
schema_3_files = os.listdir(schema_3_dir)
version_filename = f"{version}.json" if version else max(schema_3_files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a couple of minor code-level nitpicks:

  1. As a general habit in Python, I think we should favor writing if version as if version is not None. Because version is an int, so if version would behave unexpectedly if somebody supplied version=0. Granted, I don't think any labware will actually have a version 0, so it probably doesn't matter here, but, habits.
  2. max(schema_3_files) would accidentally favor 2.json over 10.json (it will return the lexicographic maximum, not the numeric maximum). I'd also worry about it accidentally picking up things like .gitignore and .DS_Store. If we want to find the highest-numbered JSON file, I think we should filter the filenames by regex and extract properly comparable ints from them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate a bit on the context of this change and its intended effect?

Right now:

  • For apiLevel ≥2.14 Python protocols, I don't think this will change anything, because of this higher-up code that sets version explicitly.
  • For apiLevel ≤2.13 Python protocols, because of this code, I think it will change their behavior from defaulting to labware version 1, to defaulting to the highest labware version, but only if the labware happens to have a schema 3 definition. (Example reproduction case.) That is probably not what we want, is it? I wouldn't think we want those protocols to be affected at all.

In my opinion:

  • In terms of overall system behavior, we want the default labware version to be a higher-level concern, so it can change depending on higher-level concepts such as the protocol's apiLevel. Here's my thinking on this from a while ago.
  • In terms of code implementation, a good way to organize that would be:
    • These functions primarily take fully-resolved, explicit namespace+load_name+version params, never assuming any default. Given a namespace+load_name+version, there should only be one file that matches, and that's something that we should enforce in the shared-data tests if we're not already.
    • Python protocols should automatically select a version, depending on their apiLevel. That code lives in load_labware_params.py. I do not think it's a good idea for Python protocols to automatically find the highest version of a labware, again for the reasons described here, but if we want to do it anyway, I still think the code should live in load_labware_params.py.

Comment on lines -241 to +242

namespace = namespace.lower()
def_path = _get_path_to_labware(load_name, namespace, checked_version)
def_path = _get_path_to_labware(load_name, namespace, version)
Copy link
Contributor

@SyntaxColoring SyntaxColoring Jan 8, 2025

Choose a reason for hiding this comment

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

Hang on, there are multiple places where checked_version was used in this function, and only this one is being changed to version. That means the error messages are out of sync with the version that was actually read, for one thing. But more seriously, it looks like we now have different version-defaulting behavior depending on exactly how the namespace was provided (see line 233). Is that intentional?

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.

4 participants