Repository navigation
Bug in table.getRows when using different selectedFields in consecutive calls #1433
Description
Please make sure you have searched for information in the following guides.
- Search the issues already opened: https://github.com/GoogleCloudPlatform/google-cloud-node/issues
- Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
- Check our Troubleshooting guide: https://github.com/googleapis/google-cloud-node/blob/main/docs/troubleshooting.md
- Check our FAQ: https://github.com/googleapis/google-cloud-node/blob/main/docs/faq.md
- Check our libraries HOW-TO: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md
- Check out our authentication guide: https://github.com/googleapis/google-auth-library-nodejs
- Check out handwritten samples for many of our APIs: https://github.com/GoogleCloudPlatform/nodejs-docs-samples
A screenshot that you have tested with "Try this API".
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
https://gist.github.com/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
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/jonathan-lande-cyera/900eba3c30f58394ad2bffe4f5d2dffa
OR
https://github.com/jonathan-lande-cyera/nodejs-bigquery/blob/a9b6215aecd3227e009f6808c798f4661754ab55/test/table.ts#L2193C1-L2233C8
A step-by-step description of how to reproduce the issue, based on the linked reproduction.
- Copy code from gist into
test/table.tsunderdescribe('getRows') - Run test "should return selected fields after consecutive requests"
- The test fails and an exception is raised
A clear and concise description of what the bug is, and what you expected to happen.
When calling table.getRows more than once, each time with different selectedFields - the method fails with:
TypeError: Cannot read properties of undefined (reading 'mode')
at <anonymous> (src/bigquery.ts:615:25)
at Array.map (<anonymous>)
at mergeSchema (src/bigquery.ts:612:21)
at Array.map (<anonymous>)
at Function.mergeSchemaWithRows_ (src/bigquery.ts:609:25)
at onComplete (src/table.ts:1843:23)
at <anonymous> (src/table.ts:1891:9)
at Table.table.request (test/table.ts:2220:11)
at Table.getRows (src/table.ts:1860:10)
at Table.wrapper (node_modules/@google-cloud/promisify/build/src/index.js:30:35)
at Context.<anonymous> (test/table.ts:2222:15)
at process.processImmediate (node:internal/timers:476:21)
at process.callbackTrampoline (node:internal/async_hooks:128:17)
It looks like the table object's metadata.schema.fields is affected by the previous call to getRows and becomes an empty array on the second call, causing the method to fail.
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. **
Calling getRows with valid selectedFields values corresponding to existing columns in the table shouldn't throw an exception.

Activity
alvarowolfx commentedon Feb 11, 2025
thanks @jonathan-lande-cyera in depth report. Sorry that I haven't looked at this before, I was swamped with other priorities and could give much attention to it. I've just opened #1437 to fix the issue, just waiting for some peer reviews on it.
jonathan-lande-cyera commentedon Mar 3, 2025
Thanks for your help, @alvarowolfx. Unfortunately, I'm still encountering an error when querying a table with records and repeated fields. I couldn't easily write a test to reproduce it, but I've saved the error I'm getting.
I would highly appreciate it if you could take a look.
Thanks 🙏
The error:
alvarowolfx commentedon Mar 7, 2025
Sorry for the late reply, but I managed to reproduce here @jonathan-lande-cyera, but still couldn't fix it. Might be able to land the fix in the next week.
Running this query and trying to add
nested.object.atoselectedFieldsthrows that error:alvarowolfx commentedon Mar 13, 2025
After digging more into this feature, I don't know why it was build as a client side feature. I found other flaws where for deeply nested objects, some format of
selectedFieldswas not even working properly.Like for the query
SELECT 40 as age, [STRUCT(STRUCT('1' as a, '2' as b) as object)] as nestedandselectedFields=['age', 'nested.object.b'], it is currently returning[40, {nested:{object:{b:'1'}], which is incorrect.BigQuery API on the service for
tabledata.listsupports aselectedFieldsparameter that does the conversion on the backend side. Ref - https://cloud.google.com/bigquery/docs/reference/rest/v2/tabledata/list#query-parametersI'm gonna send a PR cleaning that up and leaving all the handling to the service side.
jonathan-lande-cyera commentedon Jul 2, 2025
Hi @alvarowolfx, I think this is related to this issue.
I've encountered this error:
When calling the
table.getRowsmethod using SDK version 7.9.3.jonathan-lande-cyera commentedon Sep 9, 2025
Hi @alvarowolfx,
We're still getting this error
When using version 7.9.4
Any idea how to solve this?
alvarowolfx commentedon Sep 9, 2025
@jonathan-lande-cyera can you create a separated issue and example to reproduce the issue ? sorry that this got lost, I ended missing because it was on a close issue.