Skip to content
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

TooManyTemplateParams issue when using Google Cloud Storage SDK #9744

Closed
plsoucy-tapclicks opened this issue May 4, 2023 · 4 comments
Closed

Comments

@plsoucy-tapclicks
Copy link

Hi!

Our team is getting a TooManyTemplateParams error when calling the Google Cloud Storage SDK and we are having a hard time understanding if there is a real issue (possibly with the annotations in the Google SDK), a bug with psalm, or something else. Can you please advise?

Code (src/test.php)


use Google\Cloud\Storage\StorageClient;

$key_file = 'foo';
$gcs_path = 'bar';
$storage_client = new StorageClient(['projectId' => 1234, 'keyFilePath' => $key_file]);

$bucket = $storage_client->bucket('bucket-name');
$objects = $bucket->objects(['prefix' => $gcs_path, 'fields' => 'items,nextPageToken']);
print !empty($objects)."\n";
ERROR: TooManyTemplateParams - src/test.php:10:12 - Google\Cloud\Storage\ObjectIterator<Google\Cloud\Storage\StorageObject> has too many template params, expecting 0 (see https://psalm.dev/184)
$objects = $bucket->objects(['prefix' => $gcs_path, 'fields' => 'items,nextPageToken']);

PHP version: 8.1
Psalm version: 5.10.0@a5effd2d2dddd1a7ea7a0f6a051ce63ff979e356
Link to Google Cloud Storage SDK: https://github.com/googleapis/google-cloud-php/blob/main/Storage/src/Bucket.php

Composer.json

{
  "name": "test/psalm",
  "description": "",
  "minimum-stability": "dev",
  "prefer-stable": true,
  "require": {
    "php": "8.1.*",
    "google/cloud-storage": "^1.26"
  },
  "autoload": {
  },
  "autoload-dev": {
  },
  "require-dev": {
    "vimeo/psalm": "5.*"
  }
}

psalm.xml

<psalm
    errorLevel="1"
    resolveFromConfigFile="true"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
    findUnusedBaselineEntry="true"
>
    <projectFiles>
        <directory name="src" />
        <ignoreFiles>
            <directory name="vendor" />
        </ignoreFiles>
    </projectFiles>
</psalm>
@psalm-github-bot
Copy link

Hey @plsoucy-tapclicks, can you reproduce the issue on https://psalm.dev ?

@plsoucy-tapclicks
Copy link
Author

Note: issue is not reproducible on psalm.dev given the external SDK dependency (as far as I understand) but necessary code and steps to reproduce should be in my initial message. If anything else is needed, just let me know. Thanks!

@orklah
Copy link
Collaborator

orklah commented May 4, 2023

Basically, ObjectIterator is missing a @template annotation in its declaration: https://github.com/googleapis/google-cloud-php/blob/main/Storage/src/ObjectIterator.php

That means using ObjectIterator<...> is not permitted here: https://github.com/googleapis/google-cloud-php/blob/main/Storage/src/Bucket.php#L651

@plsoucy-tapclicks
Copy link
Author

Thanks @orklah for the explanation! I reported googleapis/google-cloud-php#6198 to the Google Cloud SDK team so they can review, and we will psalm-suppress the error in the meantime.

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

No branches or pull requests

2 participants