From 2504e4d8c5aaf5eae1afb69f24b62c77b2843d08 Mon Sep 17 00:00:00 2001 From: Jessica Gadling Date: Fri, 6 Dec 2024 08:59:30 -0800 Subject: [PATCH] fix: fix argument and return value handling for get_by_id (#1380) Fix: #1379 We broke the interface for `get_by_id` when improving the generated documentation for the client. This fixes the interface and adds a test. --- .../src/cryoet_data_portal/_models.py | 256 ++++++++++++------ .../templates/Header.jinja2 | 4 +- .../cryoet_data_portal/templates/Model.jinja2 | 8 +- .../tests/test_get_by_id.py | 7 + 4 files changed, 185 insertions(+), 90 deletions(-) create mode 100644 client/python/cryoet_data_portal/tests/test_get_by_id.py diff --git a/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py b/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py index fbc237e86..2cfa1d120 100644 --- a/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py +++ b/client/python/cryoet_data_portal/src/cryoet_data_portal/_models.py @@ -8,13 +8,15 @@ import os from datetime import date -from typing import List, Optional +from typing import Iterable, List, Optional +from cryoet_data_portal._client import Client from cryoet_data_portal._file_tools import download_directory, download_https from cryoet_data_portal._gql_base import ( BooleanField, DateField, FloatField, + GQLExpression, IntField, ItemRelationship, ListField, @@ -91,26 +93,30 @@ class Alignment(Model): is_portal_standard: bool = BooleanField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> alignments = Alignment.find(client, query_filters=[Alignment.run.name == "TS_026"]) Get all results for this type: >>> alignments = Alignment.find(client) """ - return super(Alignment, cls).find(*args, **kwargs) + return super(Alignment, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Alignment by ID: >>> alignment = Alignment.get_by_id(client, 1) print(alignment.name) """ - super(Alignment, cls).get_by_id(**kwargs) + return super(Alignment, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -194,26 +200,30 @@ class Annotation(Model): last_modified_date: date = DateField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> annotations = Annotation.find(client, query_filters=[Annotation.run.name == "TS_026"]) Get all results for this type: >>> annotations = Annotation.find(client) """ - return super(Annotation, cls).find(*args, **kwargs) + return super(Annotation, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Annotation by ID: >>> annotation = Annotation.get_by_id(client, 1) print(annotation.name) """ - super(Annotation, cls).get_by_id(**kwargs) + return super(Annotation, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -291,26 +301,30 @@ class AnnotationAuthor(Model): primary_author_status: bool = BooleanField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> annotation_authors = AnnotationAuthor.find(client, query_filters=[AnnotationAuthor.annotation.run.name._in(['TS_026', 'TS_027']), AnnotationAuthor.annotation.object_name.ilike('%membrane%')]) Get all results for this type: >>> annotation_authors = AnnotationAuthor.find(client) """ - return super(AnnotationAuthor, cls).find(*args, **kwargs) + return super(AnnotationAuthor, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationAuthor by ID: >>> annotation_author = AnnotationAuthor.get_by_id(client, 1) print(annotation_author.name) """ - super(AnnotationAuthor, cls).get_by_id(**kwargs) + return super(AnnotationAuthor, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -360,25 +374,29 @@ class AnnotationFile(Model): source: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> annotation_files = AnnotationFile.find(client) """ - return super(AnnotationFile, cls).find(*args, **kwargs) + return super(AnnotationFile, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationFile by ID: >>> annotation_file = AnnotationFile.get_by_id(client, 1) print(annotation_file.name) """ - super(AnnotationFile, cls).get_by_id(**kwargs) + return super(AnnotationFile, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -415,26 +433,30 @@ class AnnotationMethodLink(Model): link: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> annotation_method_links = AnnotationMethodLink.find(client, query_filters=[AnnotationMethodLink.annotation.run.name._in(['TS_026', 'TS_027']), AnnotationMethodLink.annotation.object_name.ilike('%membrane%')]) Get all results for this type: >>> annotation_method_links = AnnotationMethodLink.find(client) """ - return super(AnnotationMethodLink, cls).find(*args, **kwargs) + return super(AnnotationMethodLink, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationMethodLink by ID: >>> annotation_method_link = AnnotationMethodLink.get_by_id(client, 1) print(annotation_method_link.name) """ - super(AnnotationMethodLink, cls).get_by_id(**kwargs) + return super(AnnotationMethodLink, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -466,26 +488,30 @@ class AnnotationShape(Model): shape_type: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> annotation_shapes = AnnotationShape.find(client, query_filters=[AnnotationShape.annotation.run.name._in(['TS_026', 'TS_027']), AnnotationShape.annotation.object_name.ilike('%membrane%')]) Get all results for this type: >>> annotation_shapes = AnnotationShape.find(client) """ - return super(AnnotationShape, cls).find(*args, **kwargs) + return super(AnnotationShape, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an AnnotationShape by ID: >>> annotation_shape = AnnotationShape.get_by_id(client, 1) print(annotation_shape.name) """ - super(AnnotationShape, cls).get_by_id(**kwargs) + return super(AnnotationShape, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -569,25 +595,29 @@ class Dataset(Model): https_prefix: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> datasets = Dataset.find(client) """ - return super(Dataset, cls).find(*args, **kwargs) + return super(Dataset, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Dataset by ID: >>> dataset = Dataset.get_by_id(client, 1) print(dataset.name) """ - super(Dataset, cls).get_by_id(**kwargs) + return super(Dataset, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -638,7 +668,11 @@ class DatasetAuthor(Model): primary_author_status: bool = BooleanField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Filter dataset authors by attributes, including attributes in related models: @@ -646,19 +680,19 @@ def find(cls, *args, **kwargs): Get all results for this type: >>> dataset_authors = DatasetAuthor.find(client) """ - return super(DatasetAuthor, cls).find(*args, **kwargs) + return super(DatasetAuthor, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an DatasetAuthor by ID: >>> dataset_author = DatasetAuthor.get_by_id(client, 1) print(dataset_author.name) """ - super(DatasetAuthor, cls).get_by_id(**kwargs) + return super(DatasetAuthor, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -686,7 +720,11 @@ class DatasetFunding(Model): grant_id: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Filter dataset fundings by attributes, including attributes in related models: @@ -694,19 +732,19 @@ def find(cls, *args, **kwargs): Get all results for this type: >>> dataset_fundings = DatasetFunding.find(client) """ - return super(DatasetFunding, cls).find(*args, **kwargs) + return super(DatasetFunding, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an DatasetFunding by ID: >>> dataset_funding = DatasetFunding.get_by_id(client, 1) print(dataset_funding.name) """ - super(DatasetFunding, cls).get_by_id(**kwargs) + return super(DatasetFunding, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -772,25 +810,29 @@ class Deposition(Model): key_photo_thumbnail_url: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> depositions = Deposition.find(client) """ - return super(Deposition, cls).find(*args, **kwargs) + return super(Deposition, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Deposition by ID: >>> deposition = Deposition.get_by_id(client, 1) print(deposition.name) """ - super(Deposition, cls).get_by_id(**kwargs) + return super(Deposition, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -832,25 +874,29 @@ class DepositionAuthor(Model): primary_author_status: bool = BooleanField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> deposition_authors = DepositionAuthor.find(client) """ - return super(DepositionAuthor, cls).find(*args, **kwargs) + return super(DepositionAuthor, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an DepositionAuthor by ID: >>> deposition_author = DepositionAuthor.get_by_id(client, 1) print(deposition_author.name) """ - super(DepositionAuthor, cls).get_by_id(**kwargs) + return super(DepositionAuthor, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -876,25 +922,29 @@ class DepositionType(Model): type: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> deposition_types = DepositionType.find(client) """ - return super(DepositionType, cls).find(*args, **kwargs) + return super(DepositionType, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an DepositionType by ID: >>> deposition_type = DepositionType.get_by_id(client, 1) print(deposition_type.name) """ - super(DepositionType, cls).get_by_id(**kwargs) + return super(DepositionType, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -934,26 +984,30 @@ class Frame(Model): https_frame_path: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> frames = Frame.find(client, query_filters=[Frame.run.name == "TS_026"]) Get all results for this type: >>> frames = Frame.find(client) """ - return super(Frame, cls).find(*args, **kwargs) + return super(Frame, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Frame by ID: >>> frame = Frame.get_by_id(client, 1) print(frame.name) """ - super(Frame, cls).get_by_id(**kwargs) + return super(Frame, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -981,26 +1035,30 @@ class FrameAcquisitionFile(Model): https_mdoc_path: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> frame_acquisition_files = FrameAcquisitionFile.find(client, query_filters=[FrameAcquisitionFile.run.name == "TS_026"]) Get all results for this type: >>> frame_acquisition_files = FrameAcquisitionFile.find(client) """ - return super(FrameAcquisitionFile, cls).find(*args, **kwargs) + return super(FrameAcquisitionFile, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an FrameAcquisitionFile by ID: >>> frame_acquisition_file = FrameAcquisitionFile.get_by_id(client, 1) print(frame_acquisition_file.name) """ - super(FrameAcquisitionFile, cls).get_by_id(**kwargs) + return super(FrameAcquisitionFile, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1028,26 +1086,30 @@ class GainFile(Model): https_file_path: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> gain_files = GainFile.find(client, query_filters=[GainFile.run.name == "TS_026"]) Get all results for this type: >>> gain_files = GainFile.find(client) """ - return super(GainFile, cls).find(*args, **kwargs) + return super(GainFile, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an GainFile by ID: >>> gain_file = GainFile.get_by_id(client, 1) print(gain_file.name) """ - super(GainFile, cls).get_by_id(**kwargs) + return super(GainFile, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1083,25 +1145,29 @@ class PerSectionAlignmentParameters(Model): tilt_angle: float = FloatField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> per_section_alignment_parameters = PerSectionAlignmentParameters.find(client) """ - return super(PerSectionAlignmentParameters, cls).find(*args, **kwargs) + return super(PerSectionAlignmentParameters, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an PerSectionAlignmentParameters by ID: >>> per_section_alignment_parameters = PerSectionAlignmentParameters.get_by_id(client, 1) print(per_section_alignment_parameters.name) """ - super(PerSectionAlignmentParameters, cls).get_by_id(**kwargs) + return super(PerSectionAlignmentParameters, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1155,7 +1221,11 @@ class Run(Model): https_prefix: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Filter runs by attributes, including attributes in related models: @@ -1164,19 +1234,19 @@ def find(cls, *args, **kwargs): Get all results for this type: >>> runs = Run.find(client) """ - return super(Run, cls).find(*args, **kwargs) + return super(Run, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Run by ID: >>> run = Run.get_by_id(client, 1) print(run.name) """ - super(Run, cls).get_by_id(**kwargs) + return super(Run, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1281,26 +1351,30 @@ class TiltSeries(Model): aligned_tiltseries_binning: int = IntField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> tilt_series = TiltSeries.find(client, query_filters=[TiltSeries.run.name == "TS_026"]) Get all results for this type: >>> tilt_series = TiltSeries.find(client) """ - return super(TiltSeries, cls).find(*args, **kwargs) + return super(TiltSeries, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an TiltSeries by ID: >>> tilt_series = TiltSeries.get_by_id(client, 1) print(tilt_series.name) """ - super(TiltSeries, cls).get_by_id(**kwargs) + return super(TiltSeries, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1449,26 +1523,30 @@ class Tomogram(Model): last_modified_date: date = DateField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> tomograms = Tomogram.find(client, query_filters=[Tomogram.run.name == "TS_026"]) Get all results for this type: >>> tomograms = Tomogram.find(client) """ - return super(Tomogram, cls).find(*args, **kwargs) + return super(Tomogram, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an Tomogram by ID: >>> tomogram = Tomogram.get_by_id(client, 1) print(tomogram.name) """ - super(Tomogram, cls).get_by_id(**kwargs) + return super(Tomogram, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1558,25 +1636,29 @@ class TomogramAuthor(Model): primary_author_status: bool = BooleanField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: Get all results for this type: >>> tomogram_authors = TomogramAuthor.find(client) """ - return super(TomogramAuthor, cls).find(*args, **kwargs) + return super(TomogramAuthor, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an TomogramAuthor by ID: >>> tomogram_author = TomogramAuthor.get_by_id(client, 1) print(tomogram_author.name) """ - super(TomogramAuthor, cls).get_by_id(**kwargs) + return super(TomogramAuthor, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ @@ -1618,26 +1700,30 @@ class TomogramVoxelSpacing(Model): https_prefix: str = StringField() @classmethod - def find(cls, *args, **kwargs): + def find( + cls, + client: Client, + query_filters: Optional[Iterable[GQLExpression]] = None, + ): """ Examples: >>> tomogram_voxel_spacings = TomogramVoxelSpacing.find(client, query_filters=[TomogramVoxelSpacing.run.name == "TS_026"]) Get all results for this type: >>> tomogram_voxel_spacings = TomogramVoxelSpacing.find(client) """ - return super(TomogramVoxelSpacing, cls).find(*args, **kwargs) + return super(TomogramVoxelSpacing, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an TomogramVoxelSpacing by ID: >>> tomogram_voxel_spacing = TomogramVoxelSpacing.get_by_id(client, 1) print(tomogram_voxel_spacing.name) """ - super(TomogramVoxelSpacing, cls).get_by_id(**kwargs) + return super(TomogramVoxelSpacing, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ diff --git a/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Header.jinja2 b/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Header.jinja2 index 4121a7a84..36640c144 100644 --- a/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Header.jinja2 +++ b/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Header.jinja2 @@ -8,15 +8,17 @@ from __future__ import annotations import os from datetime import date -from typing import List, Optional +from typing import List, Optional, Iterable from cryoet_data_portal._file_tools import download_directory, download_https +from cryoet_data_portal._client import Client from cryoet_data_portal._gql_base import ( BooleanField, DateField, FloatField, IntField, ItemRelationship, + GQLExpression, ListRelationship, Model, StringField, diff --git a/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 b/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 index b102ad2a3..9bd54a9e7 100644 --- a/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 +++ b/client/python/cryoet_data_portal/src/cryoet_data_portal/templates/Model.jinja2 @@ -15,7 +15,7 @@ class {{ model.name }}(Model): {% endfor %} @classmethod - def find(cls, *args, **kwargs): + def find(cls, client: Client, query_filters: Optional[Iterable[GQLExpression]] = None): """ Examples: {% if model.fields | selectattr("name", "==", "dataset") | list | length %} @@ -38,19 +38,19 @@ class {{ model.name }}(Model): Get all results for this type: >>> {{model.plural_underscores}} = {{ model.name }}.find(client) """ - return super({{ model.name }}, cls).find(*args, **kwargs) + return super({{ model.name }}, cls).find(client, query_filters) find.__func__.__doc__ = Model.find.__func__.__doc__ + find.__func__.__doc__ @classmethod - def get_by_id(cls, **kwargs): + def get_by_id(cls, client: Client, id: int): """ Examples: Get an {{ model.name }} by ID: >>> {{ model.model_name_underscores }} = {{ model.name }}.get_by_id(client, 1) print({{ model.model_name_underscores }}.name) """ - super({{ model.name}}, cls).get_by_id(**kwargs) + return super({{ model.name}}, cls).get_by_id(client, id) get_by_id.__func__.__doc__ = ( Model.get_by_id.__func__.__doc__ + get_by_id.__func__.__doc__ diff --git a/client/python/cryoet_data_portal/tests/test_get_by_id.py b/client/python/cryoet_data_portal/tests/test_get_by_id.py new file mode 100644 index 000000000..31f2f8a05 --- /dev/null +++ b/client/python/cryoet_data_portal/tests/test_get_by_id.py @@ -0,0 +1,7 @@ +from cryoet_data_portal import Dataset +from cryoet_data_portal._client import Client + + +def test_get_by_id(client: Client) -> None: + dataset = Dataset.get_by_id(client, 20001) + assert dataset.id == 20001