Skip to content

fix(artifacts): treat session_id=None as the user namespace - #7599

Open
ankit2235 wants to merge 1 commit into
google:mainfrom
ankit2235:fix/artifacts-no-session-user-namespace
Open

ankit2235 wants to merge 1 commit into
google:mainfrom
ankit2235:fix/artifacts-no-session-user-namespace

Conversation

@ankit2235

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

2. Or, if no issue exists, describe the change:

Problem:
BaseArtifactService documents session_id=None as the user-scoped namespace ("If None, the artifact is user-scoped"), and so does the artifact service guide ("an optional session_id, where None means the user-scoped namespace"). FileArtifactService follows that: an artifact saved with session_id=None is the same one sessions reach as user:<name>, with shared versions.

InMemoryArtifactService and GcsArtifactService instead raise InputValidationError: Session ID must be provided for session-scoped artifacts. for any filename without the user: prefix, on save, load, list_versions, delete and the version lookups. So the same call works against local files and fails in memory and on GCS:

await service.save_artifact(app_name="app", user_id="u", session_id=None,
                            filename="u.txt", artifact=part)
# FileArtifactService: 0
# InMemoryArtifactService / GcsArtifactService: InputValidationError

Solution:
When session_id is None, both services now route a bare filename to the user namespace, the same storage path user:<name> already uses, instead of raising. Calls that used to fail now behave like FileArtifactService; nothing that worked before changes. app_name/user_id validation is unchanged, and session_id validation still runs whenever a session id is given.

FileArtifactService lists a session-less save under its bare name rather than with the user: prefix. The interface docstring allows that, so I left it alone.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added test_no_session_id_addresses_user_namespace, parametrized over the in-memory, GCS and file services. It saves with session_id=None, reads and re-saves through user: from a session, checks the shared versions and deletes through session_id=None.

# without the fix
pytest tests/unittests/artifacts/test_artifact_service.py::test_no_session_id_addresses_user_namespace
2 failed, 1 passed     (IN_MEMORY and GCS: InputValidationError)

# with the fix
3 passed

pytest tests/unittests/artifacts -n 4
1125 passed

Manual End-to-End (E2E) Tests:

Not run against a real GCS bucket; the GCS case runs on the test suite's mocked client, like the existing GCS tests.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

BaseArtifactService documents session_id=None as the user-scoped
namespace, and FileArtifactService behaves that way: an artifact saved
without a session is the one sessions reach through the "user:" prefix.
InMemoryArtifactService and GcsArtifactService raised InputValidationError
for any filename without the prefix instead, so the same call worked
against local files and failed in memory and on GCS.

Route a session-less filename to the user namespace in both services, as
if it carried the "user:" prefix.

@BichengWang BichengWang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit e2b9b29. No blocking findings in the namespace routing change.

I independently ran the new parametrized test against base a6ed859: memory and GCS fail with InputValidationError, while file storage passes. At this head, all three cases pass, and pytest tests/unittests/artifacts -q -n 4 passes 1,125 tests on Python 3.13.16.

Additional offline probes checked a prefixed save followed by a session-less read and save, nested filenames, shared version metadata/canonical URIs, and app/user/session isolation across all three services. User-scoped artifact:// references with bare filenames also resolve in both changed backends. The normalization in the save paths keeps the existing user: storage keys and canonical URI format, while the path helpers make reads, deletion and version lookups reach those same keys.

Validation used the existing mocked GCS client; I did not exercise a live bucket or run the full multi-version tox matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants