-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
S3 client believes every object exists. #2445
Comments
Hi @manarth, Thanks for raising this. We recently implemented I think the most sensible thing to do at this point would be to add an optional argument for usage of the newer existence methods. I'll shoot to have a PR up for this within a week. |
Hi @stobrien89 – the unexpected behaviour also currently exists for the |
My current local patch checks for a /**
* Determines whether or not a resource exists using a command
*
* @param CommandInterface $command Command used to poll for the resource
*
* @return bool
* @throws S3Exception|\Exception if there is an unhandled exception
*/
private function checkExistenceWithCommand(CommandInterface $command)
{
try {
$result = $this->execute($command);
return $result->get('@metadata')['statusCode'] !== 404;
} catch (S3Exception $e) { This works for me locally for now, although I'm not sure whether this aligns with the SDK design philosophy. |
Hi @manarth, Could you describe the unexpected behavior that's occurring when you use |
The same as above: checking for a non-existing key, in an existing bucket, returns TRUE – i.e. it believes the object exists. $result = $s3Client->doesObjectExistV2("bucket-which-exists", "dsbhjbsdhjdbfjhs");
var_dump($result);
// bool(true) |
Hi @manarth, Thanks for confirming. I think it'd be helpful for us to take a look at the debug logs here— we definitely want to correct this if there's something wrong with the implementation. Could you post the S3 response from the debug logs after adding |
This issue has not recieved a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled. |
Describe the bug
When invoking 'doesObjectExist()` with the S3 client, the API returns TRUE for non-existing objects.
Expected Behavior
The API should return TRUE if the specified bucket and key exists.
The API should return FALSE if the specified bucket does not exist, or if the specified bucket and key do not exist.
Current Behavior
The API always returns true.
Reproduction Steps
Possible Solution
The method
checkExistenceWithCommand()
in theS3ClientTrait
executes a defined command.If the command does not throw an exception, TRUE is returned.
The
doesObjectExist()
method uses aHeadObject
command to check if the bucket exists.When executing a
HeadObject
command for a non-existing key, the command does not throw an Exception.Instead, it returns the
404
response as anAws\Result
object.Additional Information/Context
The most significant end-user impact is that using
mkdir()
with the S3 StreamWrapper always fails, because it always believes the (pseudo)-directory exists.Solution options may include:
checkExistenceWithCommand()
, test for a 404 result (in addition to detecting an exception).HeadObject
command, throw an Exception for non-existing objects.SDK version used
3.222.6
Environment details (Version of PHP (
php -v
)? OS name and version, etc.)PHP 7.4.29 (cli), on Ubuntu Bionic 18.04.
The text was updated successfully, but these errors were encountered: