Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(google): Support Table objects in BigQueryHook.create_table table_resource - #73099

Open
X33834 wants to merge 1 commit into
apache:mainfrom
X33834:fix-bigquery-create-table
Open

fix(google): Support Table objects in BigQueryHook.create_table table_resource#73099
X33834 wants to merge 1 commit into
apache:mainfrom
X33834:fix-bigquery-create-table

Conversation

@X33834

@X33834 X33834 commented Sep 13, 2026

Copy link
Copy Markdown

Problem

Closes: #73091

BigQueryHook.create_table()'s table_resource parameter is typed and documented to accept a dict, Table, TableReference, or TableListItem, but the implementation only worked with a plain dict:

  • Table instance: Table.from_api_repr() was called backwards (it expects an API-JSON dict, not a Table object) → TypeError: argument of type 'Table' is not iterable
  • TableReference / TableListItem: raw **-unpacking on a non-mapping → TypeError: 'TableReference' object is not a mapping

This is reachable from BigQueryCreateTableOperator, which has the identical type hint and forwards table_resource straight into the hook. A DAG author who follows the documented type hint and passes a Table obtained from get_table() / list_tables() hits a crash.

Solution

Convert any object input to a plain dict via .to_api_repr() before merging schema_fields and building the final Table. A bare TableReference is wrapped under "tableReference" since its to_api_repr() is flat, unlike Table / TableListItem.

Tests

Added unit tests in TestTableOperations covering all four input forms (dict, Table, TableReference, TableListItem) plus schema merging:

  • test_create_table_with_table_object
  • test_create_table_with_table_reference_object
  • test_create_table_with_table_list_item
  • test_create_table_with_table_object_and_schema_fields

Ran locally: conversion logic verified against real google.cloud.bigquery objects; ruff check and py_compile clean. Full provider test suite runs in CI via breeze.

…_resource

The `table_resource` parameter is typed and documented to accept a dict,
`Table`, `TableReference`, or `TableListItem`, but the implementation only
worked with a plain dict. `Table.from_api_repr()` was called backwards on a
`Table` instance (TypeError) and raw `**`-unpacking was applied to
`TableReference`/`TableListItem` objects (TypeError: not a mapping).

Convert any object input to a plain dict via `.to_api_repr()`, wrapping a
bare `TableReference` under `"tableReference"` since its serialization is
flat, before merging `schema_fields`.

Add unit tests covering dict, Table, TableReference, TableListItem inputs
and schema merging.

Closes: apache#73091
@X33834
X33834 requested a review from shahar1 as a code owner September 13, 2026 17:22
@boring-cyborg boring-cyborg Bot added area:providers provider:google Google (including GCP) related issues labels Sep 13, 2026
@boring-cyborg

boring-cyborg Bot commented Sep 13, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to Apache Airflow!
Before letting maintainers to review your PR:

  1. Please add AI attribution as part of the PR body according to the PR template.
  2. We don't use conventional commits - please remove fix(google): from title.

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

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQueryHook.create_table() crashes when table_resource is a Table, TableReference, or TableListItem instead of a dict

2 participants