Skip to content

Commit

Permalink
Improve finding objects in default workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Dec 8, 2022
1 parent 0aafb0c commit 87646e1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use patch releases for compatibility fixes instead.

## Unreleased

### Fixed

- Improved `Beaker.(dataset|experiment|image).get()` when looking up objects in the default workspace that were created by other users.

## [v1.12.0](https://github.com/allenai/beaker-py/releases/tag/v1.12.0) - 2022-11-23

### Added
Expand Down
8 changes: 7 additions & 1 deletion beaker/services/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ def _get(id: str) -> Dataset:
return _get(dataset)
except DatasetNotFound:
if "/" not in dataset:
# Now try with adding the account name.
# Try with adding the account name.
try:
return _get(f"{self.beaker.account.name}/{dataset}")
except DatasetNotFound:
pass

# Try searching the default workspace.
if self.config.default_workspace is not None:
matches = self.beaker.workspace.datasets(match=dataset, limit=1)
if matches:
return matches[0]
raise

def create(
Expand Down
8 changes: 7 additions & 1 deletion beaker/services/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ def _get(id: str) -> Experiment:
return _get(experiment)
except ExperimentNotFound:
if "/" not in experiment:
# Now try with adding the account name.
# Try with adding the account name.
try:
return _get(f"{self.beaker.account.name}/{experiment}")
except ExperimentNotFound:
pass

# Try searching the default workspace.
if self.config.default_workspace is not None:
matches = self.beaker.workspace.experiments(match=experiment, limit=1)
if matches:
return matches[0]
raise

def create(
Expand Down
2 changes: 1 addition & 1 deletion beaker/services/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _get(id: str) -> Group:
return _get(group)
except GroupNotFound:
if "/" not in group:
# Now try with adding the account name.
# Try with adding the account name.
try:
return _get(f"{self.beaker.account.name}/{group}")
except GroupNotFound:
Expand Down
8 changes: 7 additions & 1 deletion beaker/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ def _get(id: str) -> Image:
return _get(image)
except ImageNotFound:
if "/" not in image:
# Now try with adding the account name.
# Try with adding the account name.
try:
return _get(f"{self.beaker.account.name}/{image}")
except ImageNotFound:
pass

# Try searching the default workspace.
if self.config.default_workspace is not None:
matches = self.beaker.workspace.images(match=image, limit=1)
if matches:
return matches[0]
raise

def create(
Expand Down

0 comments on commit 87646e1

Please sign in to comment.