GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — client.insert_rows should fail when inserting non-existing fields · Issue #151 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

client.insert_rows should fail when inserting non-existing fields #151

Copy link
Copy link
Closed
#163
Closed
client.insert_rows should fail when inserting non-existing fields#151
#163
Copy link
Assignees
plamut
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@simonvanderveldt
simonvanderveldt
opened on Jun 26, 2020
Issue body actions

Version

google-cloud-bigquery==1.25.0

The client.insert_rows() function doesn't fail when inserting non-existing fields whereas the BigQuery API does fail with a message like

{
  "kind": "bigquery#tableDataInsertAllResponse",
  "insertErrors": [
    {
      "index": 0,
      "errors": [
        {
          "reason": "invalid",
          "location": "zap",
          "debugInfo": "",
          "message": "no such field."
        }
      ]
    }
  ]
}

insert_rows() silently drops the additional columns instead.

This happens because insert_rows() uses _record_field_to_json which only iterates over the list of fields that are provided ignoring all the other fields that are part of the data and insert_rows() passes the table's schema as list of fields to _record_field_to_json.

This behavior is opposite to the BigQuery API and means we cannot reliably insert data because we're not made aware of changes to the incoming data because there's no failure.
IMHO this behavior is not correct, I think it would be OK if selected_fields was provided but it should not silently use the schema to limit which of the fields of the input data are processed and ignore the rest.
I can image there might be cases where one wants to be lenient/ignore all fields that are not part of table so this behavior might have to be an option, possibly combined with selected_fields.

P.S. By extension this also applies to the client.insert_rows_from_dataframe() function which uses client.insert_rows().

P.P.S We initially ran into this when using insert_rows_from_dataframe() and it was a bit of a search to find where this was going wrong because it's a somewhat indirect chain of insert_rows_from_dataframe -> insert_rows -> insert_rows_json.
Why was this long way chosen/added instead of simply using insert_rows_json(table, df.to_dict(orient="records"))? It seems a lot simpler and will probably be the workaround we'll implement for now.

Activity

  1. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    on Jun 26, 2020
  2. meredithslota
    assigned
    plamut
    on Jun 26, 2020
  3. meredithslota commented on Jun 26, 2020

    @meredithslota
    meredithslota
    on Jun 26, 2020
    Contributor
    More actions

    @plamut Can you take a look?

  4. yoshi-automation
    added
    triage meI really want to be triaged.
    on Jun 27, 2020
  5. plamut
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    triage meI really want to be triaged.
    on Jun 29, 2020
  6. plamut commented on Jun 29, 2020

    @plamut
    plamut
    on Jun 29, 2020
    Contributor
    More actions

    I can confirm the reported behavior, will check how to make the method fail on non-existing fields.

    it's a somewhat indirect chain of insert_rows_from_dataframe -> insert_rows -> insert_rows_json.
    Why was this long way chosen/added instead of simply using insert_rows_json(table, df.to_dict(orient="records"))?

    IIRC there was a memory concern for large dataframes - df.to_dict(orient="records") would convert the entire dataframe to a list of row dicts, while insert_rows_from_dataframe() only processes and inserts chunk_size rows at a time.

    Reacted by Simon van der Veldt
  7. tseaver
    closed this as completedin #163on Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @plamut
    plamut

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.