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

Include existing IDs in python API client docs for get_by_id #1381

Open
uermel opened this issue Dec 6, 2024 · 3 comments
Open

Include existing IDs in python API client docs for get_by_id #1381

uermel opened this issue Dec 6, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@uermel
Copy link
Contributor

uermel commented Dec 6, 2024

The python API client now has Model-specific docs for every Model it supports. While the examples for get_by_id do contain working code, it would be great if the queries they imply would actually return data instead of None. This is done in the case of find to some extent.

Right now, for the majority of Models, the example in Model.get_by_id uses id=1, which will return None for most models, because that ID in most cases is not used.

To reproduce:

import sys
import inspect
import cryoet_data_portal as cdp

classes = [obj for name, obj in inspect.getmembers(sys.modules[cdp._models.__name__], inspect.isclass)
          if obj.__module__ is cdp._models.__name__]

client = cdp.Client()

for c in classes:
    ret = c.get_by_id(client, 1) is None
    print(f"{c.__name__}.get_by_id(client, 1) is None == {ret}")

Returns:

Alignment.get_by_id(client, 1) is None == True
Annotation.get_by_id(client, 1) is None == True
AnnotationAuthor.get_by_id(client, 1) is None == True
AnnotationFile.get_by_id(client, 1) is None == True
AnnotationMethodLink.get_by_id(client, 1) is None == True
AnnotationShape.get_by_id(client, 1) is None == True
Dataset.get_by_id(client, 1) is None == True
DatasetAuthor.get_by_id(client, 1) is None == True
DatasetFunding.get_by_id(client, 1) is None == True
Deposition.get_by_id(client, 1) is None == True
DepositionAuthor.get_by_id(client, 1) is None == False
DepositionType.get_by_id(client, 1) is None == True
Frame.get_by_id(client, 1) is None == True
FrameAcquisitionFile.get_by_id(client, 1) is None == True
GainFile.get_by_id(client, 1) is None == True
PerSectionAlignmentParameters.get_by_id(client, 1) is None == False
Run.get_by_id(client, 1) is None == True
TiltSeries.get_by_id(client, 1) is None == True
Tomogram.get_by_id(client, 1) is None == True
TomogramAuthor.get_by_id(client, 1) is None == True
TomogramVoxelSpacing.get_by_id(client, 1) is None == True
@uermel uermel added the bug Something isn't working label Dec 6, 2024
@uermel uermel changed the title Further improve python API client docs for get_by_id Include existing IDs in python API client docs for get_by_id Dec 6, 2024
@andy-sweet
Copy link
Contributor

andy-sweet commented Dec 6, 2024

If I remember correctly, some of the IDs may not be stable (i.e. they may change over time), so manually defining these once would be fragile.

It might be possible for the code generator to find the first instance of each model type and use that ID value, but that would also need to be run any time those IDs actually change, so might not be much better (unless we only expect ID value changes to coincide with API releases, in which case we could just re-run code generation at release time).

@uermel
Copy link
Contributor Author

uermel commented Dec 6, 2024

That's true, but at least for Depositions, Datasets, Runs, and Tomograms I believe IDs should be pretty stable by now. I think in those cases (which I expect would be the most frequently used) we could use working IDs.

@melissawm
Copy link
Collaborator

@dgmccart had mentioned you might have a number that works everytime (something like 10000) but I can't reproduce that. I also looked at the test_get_by_id.py file which lists 20001 for the Dataset object but that doesn't seem to work for me either??

Any tips on how to pick those ids?

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

No branches or pull requests

3 participants