Problem
S3FileSystem.info(path, version_id=...) returns cached metadata of a different version. After info(p, version_id="v1"), a call to info(p, version_id="v2") returns v1's size, ETag and version_id instead of v2's.
Expected: an explicit version_id is honored, either by matching it against the cached entry or by bypassing the cache.
From the code on master (775874c):
_head_object() caches the result under the path without the version (self.dircache[path] = file) and returns a cached entry whenever path in self.dircache, without comparing the requested version_id.
- In
info(), a cached entry is returned as is unless the filesystem is version aware, the call has no version_id, and the cached entry has none either. Calls with a different explicit version_id therefore get the cached entry.
Found by code reading during the review of #928 (not reproduced live yet).
Reproduction
from pyathena import connect
from pyathena.filesystem.s3 import S3FileSystem
fs = S3FileSystem(connect(), version_aware=True, skip_instance_cache=True)
path = "s3://VERSIONED_BUCKET/tmp/key"
fs.pipe(path, b"1")
v1 = fs.info(path, refresh=True)["version_id"]
fs.pipe(path, b"22")
v2 = fs.info(path, refresh=True)["version_id"]
fs.invalidate_cache()
print(fs.info(path, version_id=v1)["size"]) # 1
print(fs.info(path, version_id=v2)["size"]) # expected 2, returns 1 from the cache
Environment
- PyAthena master 775874c,
S3FileSystem with version_aware=True.
Proposed fix (optional)
When a version_id is requested (as an argument or in the path), use the cached entry only if its version_id matches; otherwise head the object with that version. Add a test that reads two versions of the same object through one instance.
Problem
S3FileSystem.info(path, version_id=...)returns cached metadata of a different version. Afterinfo(p, version_id="v1"), a call toinfo(p, version_id="v2")returns v1's size, ETag andversion_idinstead of v2's.Expected: an explicit
version_idis honored, either by matching it against the cached entry or by bypassing the cache.From the code on master (775874c):
_head_object()caches the result under the path without the version (self.dircache[path] = file) and returns a cached entry wheneverpath in self.dircache, without comparing the requestedversion_id.info(), a cached entry is returned as is unless the filesystem is version aware, the call has noversion_id, and the cached entry has none either. Calls with a different explicitversion_idtherefore get the cached entry.Found by code reading during the review of #928 (not reproduced live yet).
Reproduction
Environment
S3FileSystemwithversion_aware=True.Proposed fix (optional)
When a
version_idis requested (as an argument or in the path), use the cached entry only if itsversion_idmatches; otherwise head the object with that version. Add a test that reads two versions of the same object through one instance.