Merge pull request #12778 from jmchilton/type_fixes_managers_1

More Python type fixes from deferred data branch.
This commit is contained in:
David López
2021-10-25 20:31:49 +02:00
committed by GitHub
5 changed files with 21 additions and 15 deletions
+11 -8
View File
@@ -16,15 +16,18 @@ have nothing to do with the web - keep this in mind when defining exception name
and messages.
"""
from ..exceptions.error_codes import error_codes_by_name
from ..exceptions.error_codes import (
error_codes_by_name,
ErrorCode,
)
class MessageException(Exception):
"""Most generic Galaxy exception - indicates merely that some exceptional condition happened."""
# status code to be set when used with API.
status_code = 400
status_code: int = 400
# Error code information embedded into API json responses.
err_code = error_codes_by_name['UNKNOWN']
err_code: ErrorCode = error_codes_by_name['UNKNOWN']
def __init__(self, err_msg=None, type="info", **extra_error_info):
self.err_msg = err_msg or self.err_code.default_error_message
@@ -253,7 +256,7 @@ class ServerNotConfiguredForRequest(MessageException):
class ContainerCLIError(Exception):
def __init__(self, msg=None, stdout=None, stderr=None, returncode=None,
command=None, subprocess_command=None, **kwargs):
super().__init__(msg, **kwargs)
super().__init__(msg)
self.stdout = stdout
self.stderr = stderr
self.returncode = returncode
@@ -263,24 +266,24 @@ class ContainerCLIError(Exception):
class ContainerNotFound(Exception):
def __init__(self, msg=None, container_id=None, **kwargs):
super().__init__(msg, **kwargs)
super().__init__(msg)
self.container_id = container_id
class ContainerImageNotFound(Exception):
def __init__(self, msg=None, image=None, **kwargs):
super().__init__(msg, **kwargs)
super().__init__(msg)
self.image = image
class ContainerRunError(Exception):
def __init__(self, msg=None, image=None, command=None, **kwargs):
super().__init__(msg, **kwargs)
super().__init__(msg)
self.image = image
self.command = command
class HandlerAssignmentError(Exception):
def __init__(self, msg=None, obj=None, **kwargs):
super().__init__(msg, **kwargs)
super().__init__(msg)
self.obj = obj
+6 -3
View File
@@ -4,7 +4,7 @@ Manager and Serializer for Datasets.
import glob
import logging
import os
from typing import Type
from typing import List, Type
from galaxy import (
exceptions,
@@ -30,6 +30,7 @@ class DatasetManager(base.ModelManager, secured.AccessibleManagerMixin, deletabl
"""
model_class = model.Dataset
foreign_key_name = 'dataset'
app: MinimalManagerApp
# TODO:?? get + error_if_uploading is common pattern, should upload check be worked into access/owed?
@@ -235,6 +236,7 @@ class DatasetAssociationManager(base.ModelManager,
# DA's were meant to be proxies - but were never fully implemented as them
# Instead, a dataset association HAS a dataset but contains metadata specific to a library (lda) or user (hda)
model_class: Type[model.DatasetInstance] = model.DatasetInstance
app: MinimalManagerApp
# NOTE: model_manager_class should be set in HDA/LDA subclasses
@@ -692,6 +694,7 @@ class DatasetAssociationDeserializer(base.ModelDeserializer, deletable.PurgableD
sa_session = self.app.model.context
sa_session.flush()
trans = context.get("trans")
assert trans, "Logic error in Galaxy, deserialize_datatype not send a transation object" # TODO: restructure this for stronger typing
job, *_ = self.app.datatypes_registry.set_external_metadata_tool.tool_action.execute(self.app.datatypes_registry.set_external_metadata_tool, trans, incoming={'input1': item}, overwrite=False) # overwrite is False as per existing behavior
trans.app.job_manager.enqueue(job, tool=trans.app.datatypes_registry.set_external_metadata_tool)
return item.datatype
@@ -731,9 +734,9 @@ class DatasetAssociationFilterParser(base.ModelFilterParser, deletable.PurgableF
datatypes in the comma separated string `class_strs`?
"""
parse_datatype_fn = self.app.datatypes_registry.get_datatype_class_by_name
comparison_classes = []
comparison_classes: List[Type] = []
for class_str in class_strs.split(','):
datatype_class = parse_datatype_fn(class_str)
if datatype_class:
comparison_classes.append(datatype_class)
return comparison_classes and isinstance(dataset_assoc.datatype, comparison_classes)
return comparison_classes and isinstance(dataset_assoc.datatype, tuple(comparison_classes))
+1
View File
@@ -43,6 +43,7 @@ class HDAManager(datasets.DatasetAssociationManager,
tag_assoc = model.HistoryDatasetAssociationTagAssociation
annotation_assoc = model.HistoryDatasetAssociationAnnotationAssociation
app: MinimalManagerApp
# TODO: move what makes sense into DatasetManager
# TODO: which of these are common with LDDAs and can be pushed down into DatasetAssociationManager?
+3
View File
@@ -13,6 +13,7 @@ from galaxy.model.mapping import GalaxyModelMapping
from galaxy.model.security import GalaxyRBACAgent
from galaxy.model.security import HostAgent
from galaxy.model.tags import GalaxyTagHandler
from galaxy.objectstore import ObjectStore
from galaxy.quota import QuotaAgent
from galaxy.security.idencoding import IdEncodingHelper
from galaxy.tool_util.deps.views import DependencyResolversView
@@ -49,6 +50,7 @@ class MinimalApp(BasicApp):
install_model: ModelMapping
security_agent: GalaxyRBACAgent
host_security_agent: HostAgent
object_store: ObjectStore
class MinimalManagerApp(MinimalApp):
@@ -64,6 +66,7 @@ class MinimalManagerApp(MinimalApp):
role_manager: Any # 'galaxy.managers.roles.RoleManager'
installed_repository_manager: Any # 'galaxy.tool_shed.galaxy_install.installed_repository_manager.InstalledRepositoryManager'
user_manager: Any
job_manager: Any # galaxy.jobs.manager.JobManager
@property
def is_job_handler(self) -> bool:
-4
View File
@@ -249,8 +249,6 @@ check_untyped_defs = False
check_untyped_defs = False
[mypy-galaxy.job_metrics]
check_untyped_defs = False
[mypy-galaxy.exceptions]
check_untyped_defs = False
[mypy-galaxy.datatypes.display_applications.parameters]
check_untyped_defs = False
[mypy-tool_shed.webapp.search.tool_search]
@@ -591,8 +589,6 @@ check_untyped_defs = False
check_untyped_defs = False
[mypy-galaxy.metadata.set_metadata]
check_untyped_defs = False
[mypy-galaxy.managers.datasets]
check_untyped_defs = False
[mypy-galaxy.managers.lddas]
check_untyped_defs = False
[mypy-galaxy.tools.error_reports]