feat: implement storage context and billing project for gcs#18
Open
project-defiant wants to merge 3 commits intoopentargets:mainfrom
Open
feat: implement storage context and billing project for gcs#18project-defiant wants to merge 3 commits intoopentargets:mainfrom
project-defiant wants to merge 3 commits intoopentargets:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a generic storage context mechanism to pass backend-specific options (notably GCS requester-pays billing_project) through tasks into storage backends without changing existing storage API signatures.
Changes:
- Added a
storage_contextContextVar-based context manager plus settings models for backend-specific configuration. - Updated Google Cloud Storage backends (sync + async) to apply
billing_projectto bucket creation / request headers and query params. - Updated
copyandcopy_manytasks to accept optional settings and execute within the storage context; added/expanded tests for context usage and GCS request injection.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Bumped editable package version recorded in the lockfile. |
| pyproject.toml | Updated project version metadata. |
| src/otter/storage/storage_context.py | Added ContextVar-backed storage context manager and accessor. |
| src/otter/storage/model.py | Introduced base StorageSettings Pydantic model for context settings validation. |
| src/otter/storage/settings/init.py | Added GoogleStorageSettings (billing project). |
| src/otter/storage/synchronous/model.py | Added hook for backends to provide a context settings validation model. |
| src/otter/storage/asynchronous/model.py | Added hook for async backends to provide a context settings validation model. |
| src/otter/storage/synchronous/handle.py | Validates active context settings against the backend model when creating handles. |
| src/otter/storage/asynchronous/handle.py | Validates active context settings against the backend model when creating async handles. |
| src/otter/storage/synchronous/google.py | Uses storage context billing project when creating buckets (user_project). |
| src/otter/storage/asynchronous/google.py | Injects billing project into headers/params; refactors listing logic to list_objects. |
| src/otter/tasks/copy.py | Adds optional settings and runs copy/validation inside storage_context. |
| src/otter/tasks/copy_many.py | Adds optional settings and resolves/copies sources inside storage_context. |
| src/otter/util/errors.py | Added StorageContextSettingsError. |
| test/task/test_copy.py | Added tests asserting storage_context is used in copy run/validate. |
| test/task/test_copy_many.py | Added tests asserting storage_context is used in copy_many. |
| test/storage/synchronous/test_storage_google.py | Added sync GCS test verifying user_project uses billing project context. |
| test/storage/asynchronous/test_storage_google.py | Updated async GCS tests and added context header/param assertions for read/copy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR involves changes to opentargets/issues#4321
Feature
StorageContextcontext manager so backend-specific options can be passed through execution the task to the storage handler classes without changing storage API signatures.StorageSettingsmodel that shall be extended with custom settings that are needed by the specific StorageHandlers.billing_projectused by GoogleStorage classes to inject the project in case the bucket is requester pays.Example config used to test
Google Backend Behavior
billing_projectfrom StorageContext and passes it asuser_projectwhen creating Bucket object.x-goog-user-projectheaderuserProjectquery parameterAsync listing logic was updated to use
list_objectsand context-aware headers/params. (code taken from original async implementation that uses the headers, that can not be passed otherwise)Task-Level Changes
copytask now accepts optional settings and runs copy/validation inside storage context.copy_manytask now accepts optional settings and executes source resolution and async copies inside storage context.Tests
gs://open-taragets-data-releases/26.03/studybilling_projectkey, the failure with requester_pays issueNext steps
settingstogwasandcredible_setsteps.