Skip to content

Commit

Permalink
Rework for changes to our SA handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Feb 21, 2024
1 parent 2f69f57 commit a15a209
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/galaxy/managers/object_store_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from galaxy.exceptions import (
ItemOwnershipException,
RequestParameterMissingException,
RequestParameterInvalidException,
)
from galaxy.managers.context import ProvidesUserContext
from galaxy.model import (
Expand Down Expand Up @@ -61,7 +62,7 @@ class CreateInstancePayload(BaseModel):
class UpdateInstancePayload(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
variables: Optional[Dict[str, ObjectStoreTemplateVariableValueType]]
variables: Optional[Dict[str, ObjectStoreTemplateVariableValueType]] = None


class UpdateInstanceSecretPayload(BaseModel):
Expand Down Expand Up @@ -123,7 +124,7 @@ def _upgrade_instance(
catalog = self._catalog
template = catalog.find_template_by(persisted_object_store.object_store_template_id, payload.template_version)
persisted_object_store.object_store_template_version = template.version
persisted_object_store.object_store_template_definition = template.dict()
persisted_object_store.object_store_template_definition = template.model_dump()
old_variables = persisted_object_store.object_store_template_variables
updated_variables = payload.variables
actual_variables = {}
Expand Down Expand Up @@ -202,7 +203,8 @@ def create_instance(
user_vault = trans.user_vault
persisted_object_store = UserObjectStore()
persisted_object_store.user_id = trans.user.id
persisted_object_store.object_store_template_definition = template.dict()
assert persisted_object_store.user_id
persisted_object_store.object_store_template_definition = template.model_dump()
persisted_object_store.object_store_template_id = template.id
persisted_object_store.object_store_template_version = template.version
persisted_object_store.object_store_template_variables = payload.variables
Expand Down Expand Up @@ -242,9 +244,12 @@ def show(self, trans: ProvidesUserContext, id: Union[str, int]) -> UserConcreteO
def _save(self, persisted_object_store: UserObjectStore) -> None:
self._sa_session.add(persisted_object_store)
self._sa_session.flush([persisted_object_store])
self._sa_session.commit()

def _get(self, trans: ProvidesUserContext, id: Union[str, int]) -> UserObjectStore:
user_object_store = self._sa_session.query(UserObjectStore).get(int(id))
if user_object_store is None:
raise RequestParameterInvalidException(f"Failed to fetch object store for id {id}")
if user_object_store.user != trans.user:
raise ItemOwnershipException()
return user_object_store
Expand Down

0 comments on commit a15a209

Please sign in to comment.