Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Problem with createDataset

Open
#7,614 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
google-cloud, php
Domain
api, cloud

Research direction

Start with samples/V1/DatasetServiceClient/create_dataset.php and trace the createDataset call into vendor/google/gax/src/RequestBuilder.php:174, where the reported warning occurs. Reproduce the tabular dataset request with the stated PHP and package versions, then verify that the example completes without the foreach warning and creates the dataset.

Written by the indexing model from the issue text.

Description

Environment details
  • OS: Windows 10
  • PHP version: 8.2.12
  • Package name and version: cloud-ai-platform v.1.3
Steps to reproduce
  1. I'm use the example https://github.com/googleapis/google-cloud-php-ai-platform/blob/main/samples/V1/DatasetServiceClient/create_dataset.php for create a Dataset for Tabular data, when I called the example I have the next error:
foreach() argument must be of type array|object, null given

  at vendor\google\gax\src\RequestBuilder.php:174
    170▕
    171▕         $body = null;
    172▕         $queryParams = [];
    173▕         $messageData = json_decode($messageDataJson, true);
  ➜ 174▕         foreach ($messageData as $name => $value) {
    175▕             if (array_key_exists($name, $config['placeholders'])) {
    176▕                 continue;
    177▕             }
    178▕

  1   vendor\google\gax\src\RequestBuilder.php:174
      Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}("foreach() argument must be of type array|object, null given", "C:\...\vendor\google\gax\src\RequestBuilder.php")

  2   vendor\google\gax\src\RequestBuilder.php:110
      Google\ApiCore\RequestBuilder::constructBodyAndQueryParameters(Object(Google\Cloud\AIPlatform\V1\CreateDatasetRequest), ["post", "/v1/{parent=projects/*/locations/*}/datasets", "dataset"])

The code it's the same of the example https://github.com/googleapis/google-cloud-php-ai-platform/blob/main/samples/V1/DatasetServiceClient/create_dataset.php.

Code example

// The called to function are:

 $formattedParent = DatasetServiceClient::locationName('lab-ia-430919', 'us-central1');
        $this->create_dataset(
            $formattedParent,
            'example-ventas',
            'gs://bucket-ia-example/schemaDatasetVertexAI.yaml'
        );


    function create_dataset(
        string $formattedParent,
        string $datasetDisplayName,
        string $datasetMetadataSchemaUri
    ): void {
        // Create a client.
        $datasetServiceClient = new DatasetServiceClient();

        // Prepare the request message.
        $datasetMetadata = new Value();
        $dataset = (new Dataset())
            ->setName($datasetDisplayName)
            ->setDisplayName($datasetDisplayName)
            ->setMetadataSchemaUri($datasetMetadataSchemaUri)
            ->setMetadata($datasetMetadata);
        $request = (new CreateDatasetRequest())
            ->setParent($formattedParent)
            ->setDataset($dataset);


        // Call the API and handle any network failures.
        try {
            /** @var OperationResponse $response */
            $response = $datasetServiceClient->createDataset($request);
            $response->pollUntilComplete();

            if ($response->operationSucceeded()) {
                /** @var Dataset $result */
                $result = $response->getResult();
                printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
            } else {
                /** @var Status $error */
                $error = $response->getError();
                printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
            }
        } catch (ApiException $ex) {
            printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
        }
    }
    
Dominant language
PHP
Stars
1.2k
Forks
464
Avg merge
2d 4h
Merged PRs (30d)
98

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-cloud-php

All issues in googleapis/google-cloud-php

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.