Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

table.getRows throws TypeError: Cannot read properties of undefined (reading 'fields') #1452

Closed

Description

@kirstu

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

This is provably a client error as it happens only post version 7.9.2

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/kirstu/2d343883f04c7f29fc8f065b9f6928e1

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Follow steps in https://cloud.google.com/bigquery/docs/paging-results#iterate_through_client_libraries_results
  2. Observe error: "Cannot read properties of undefined (reading 'fields')"

Error is thrown from mergeSchemaWithRows_ function here. Most likely happens because this.metadata.schema is undefined here

Full stack trace

TypeError: Cannot read properties of undefined (reading 'fields')
      at Function.mergeSchemaWithRows_ (node_modules/.pnpm/@google-cloud+bigquery@7.9.2/node_modules/@google-cloud/bigquery/build/src/bigquery.js:305:35)
      at onComplete (node_modules/.pnpm/@google-cloud+bigquery@7.9.2/node_modules/@google-cloud/bigquery/build/src/table.js:972:32)
      at node_modules/.pnpm/@google-cloud+bigquery@7.9.2/node_modules/@google-cloud/bigquery/build/src/table.js:1007:13
      at node_modules/.pnpm/@google-cloud+common@5.0.2/node_modules/@google-cloud/common/build/src/util.js:412:25
      at Util.handleResp (node_modules/.pnpm/@google-cloud+common@5.0.2/node_modules/@google-cloud/common/build/src/util.js:161:9)
      at node_modules/.pnpm/@google-cloud+common@5.0.2/node_modules/@google-cloud/common/build/src/util.js:534:22
      at onResponse (node_modules/.pnpm/retry-request@7.0.2/node_modules/retry-request/index.js:259:7)
      at /Volumes/Dev/pasisalo/Projects/hox/node_modules/.pnpm/teeny-request@9.0.0/node_modules/teeny-request/src/index.ts:320:13

A clear and concise description of what the bug is, and what you expected to happen.

table.getRows should return a response, instead an error is thrown

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

The change introduced in release 7.9.2 is causing the issue. Version prior to 7.9.2 work just as expected. From the linked commit it's pretty obvious why the error happens.

Activity

  1. added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Apr 1, 2025
  2. self-assigned this
    on Apr 1, 2025
  3. alvarowolfx commented on Apr 1, 2025

    @alvarowolfx
    Contributor

    @kirstu thanks for the report. The repro snippet that you wrote was a good one to repro the error, which actually happens when trying to call getRows on a empty table, which if I understood correctly, might not be what was intended on the snippet. It is missing setting the newly created table as a destination table for the query job. Because of that, the table being fetched is always empty.

    Updated snippet that I used:

    function main(
      datasetId = 'my_dataset', // Existing dataset
      tableId = 'my_table' // Table to create
    ) {
      // [START bigquery_browse_table]
      // Import the Google Cloud client library using default credentials
      const {BigQuery} = require('@google-cloud/bigquery');
      const bqClient = new BigQuery();
    
      async function clientBug() {
        const [dataset] = await bqClient.createDataset(datasetId);
    
        await dataset.createTable(tableId, {
          schema: [{name: 'id', type: 'STRING'}],
        });
    
        const table = bqClient.dataset(datasetId).table(tableId);
    
        const [job] = await table.createQueryJob({
          query: "SELECT '1' as id",
          params: [],
          destinationTable: {
            datasetId,
            tableId,
            projectId: bqClient.projectId
          },
        });
    
        await job.getQueryResults({
          maxResults: 0,
        });
    
        const rows = await table.getRows({
            maxResults: 1337
        });
    
        console.log(JSON.stringify(rows))
      }
      clientBug();
    }
    main(...process.argv.slice(2));
    
    

    The sample in https://cloud.google.com/bigquery/docs/paging-results#iterate_through_client_libraries_results is tested in our integration tests and are working fine, I also ran it manually to double check.

    Sent a PR to solve the issue with empty table: #1455

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

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/nodejs-bigquery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions