Repository navigation
Name explicit versions in info() and record HeadObject's VersionId (GH-1529) #1618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2f0b268
961ea1c
d7820f3
01753da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,7 +269,7 @@ def to_path(self) -> S3Path: | |
| directory ``bucket/`` of the key ``/x``, names the bucket, as in | ||
| :class:`S3Path`. The entry of the root gives ``S3Path("")``. A version | ||
| ID that the entry records, such as that of a version entry or of a | ||
| ``version_aware`` lookup, is not part of the path. | ||
| HeadObject lookup, is not part of the path. | ||
|
|
||
| Returns: | ||
| The path of the bucket, the directory or the object. | ||
|
|
@@ -392,23 +392,24 @@ def from_version(cls, version: S3ObjectVersion) -> S3Object: | |
| return cls._from_listing(version, **fields) | ||
|
|
||
| @classmethod | ||
| def from_metadata(cls, metadata: S3Metadata, version_id: str | None = None) -> S3Object: | ||
| def from_metadata(cls, metadata: S3Metadata) -> S3Object: | ||
| """Build the file entry of an object looked up with HeadObject. | ||
|
|
||
| The S3 API fields that the response does not have are left out, | ||
| except ``Metadata``, which botocore always returns. ``version_id`` is | ||
| always set, to None for an entry without a version, and ``type``, | ||
| always set: to the ``VersionId`` that HeadObject returned, or else to | ||
| the version of the looked up path, or None. ``type``, | ||
| ``bucket``, ``key``, ``name``, ``size``, ``content_length`` (0 | ||
| without ``ContentLength``) and ``storage_class`` are set as the | ||
| constructor sets them. | ||
|
|
||
| Args: | ||
| metadata: The metadata of the object, with the looked up path. | ||
| version_id: The version ID of the entry, which may be pinned or | ||
| omitted apart from the looked up path. | ||
|
|
||
| Returns: | ||
| The file entry, named ``bucket/key``. | ||
| The file entry, named after the looked up path, as | ||
| :meth:`from_version` names a version: ``bucket/key?versionId=<id>`` | ||
| for a version other than ``null``, and ``bucket/key`` otherwise. | ||
|
|
||
| Raises: | ||
| ValueError: If the metadata has no object path. | ||
|
|
@@ -436,13 +437,19 @@ def from_metadata(cls, metadata: S3Metadata, version_id: str | None = None) -> S | |
| "Metadata": metadata.user_metadata, | ||
| "LastModified": metadata.last_modified, | ||
| } | ||
| return cls( | ||
| path = metadata.path | ||
| entry = cls( | ||
| init={k: v for k, v in fields.items() if v is not None}, | ||
| type=S3ObjectType.S3_OBJECT_TYPE_FILE, | ||
| bucket=metadata.path.bucket, | ||
| key=metadata.path.key, | ||
| version_id=version_id, | ||
| bucket=path.bucket, | ||
| key=path.key, | ||
| version_id=metadata.version_id or path.version_id, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed), round one. Reviewer: Codex CLI 0.172.0, Covered (as reported): Result: FINDINGS, 3 Medium and 2 Low. Repaired in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed), follow-ups. Codex CLI 0.172.0, |
||
| ) | ||
| if path.version_id and path.version_id != "null": | ||
| # The name comes from the request, the metadata from the | ||
| # response. | ||
| entry["name"] = str(path) | ||
| return entry | ||
|
|
||
| @classmethod | ||
| def from_bucket(cls, bucket: S3Bucket) -> S3Object: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R1-2 (repaired). The guide said that a listed entry has no version, but entries of
ls(versions=True)have one. It now says ListObjectsV2. It also named the entry "the same name" as the path, although?version_id=and similar spellings are normalized to?versionId=; it now gives the formbucket/key?versionId=<id>.R1-3 (repaired). The
to_path()docstring and a comment in_head_objectstill equated a recorded version with a pinned one.R1-4 (repaired). The
currentrow oftest_info_names_an_explicit_versionrepeatedtest_info_version_aware_heads_listed_file[False]'s evidence and is removed.R1-5 (kept as decided; this line). Without
version_aware,info()["version_id"]is the reported version after a HeadObject and None wheninfo()answers from a cached ListObjectsV2 listing. #1529 item 2 decided to record HeadObject's version and to keep the key sets of listed entries, so the split by source is intended. The guide now states it.R1-6 (no change). The live
test_info_fileassertsversion_id is Nonefor an unversioned path. That holds for the test environment's bucket, which is not versioned, and is the correct answer there.Self-review round two (claims, callers, operator, evidence), full pass over the repaired head:
pyathena/reads an entry'sversion_id" (grep ins3.py/s3_async.py: two readers, both gated); "to_api_repr()does not emit it" (_API_FIELD_TO_S3_OBJECT_FIELDhas noVersionId); "a later lookup of the key keeps its name" (put_lookupkeys an explicit version apart, and a test covers it).Result: CLEAN for round two.