fix(spanner-django): db_returning should only be overridden for Spanner by olavloite · Pull Request #16111 · googleapis/google-cloud-python · GitHub
Skip to content

fix(spanner-django): db_returning should only be overridden for Spanner#16111

Merged
olavloite merged 1 commit into
mainfrom
issue-15930
Mar 16, 2026
Merged

fix(spanner-django): db_returning should only be overridden for Spanner#16111
olavloite merged 1 commit into
mainfrom
issue-15930

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

The db_returning attribute of AutoFields should only be overridden for Spanner database connections, and not globally for all databases.

Note: Many tests are failing. These failures are not due to these changes, but due to existing failures for this library.

Fixes #15930

Replaces googleapis/python-spanner-django#961

The db_returning attribute of AutoFields should only be overridden for Spanner database connections,
and not globally for all databases.

Note: Many tests are failing. These failures are not due to these changes, but due to existing
failures for this library.

Fixes #15930
@olavloite olavloite requested review from a team as code owners March 16, 2026 11:00
@gemini-code-assist

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly refactors the monkey-patching of Django's AutoField to be conditional, applying Spanner-specific behavior only when a Spanner database is configured for client-side ID generation. This is a good improvement as it avoids globally altering AutoField behavior, which could impact other database backends in a multi-DB setup. The logic change in django_spanner/__init__.py is sound, and the new tests in tests/unit/django_spanner/test_schema.py provide good coverage. The minor suggestions to improve the readability and consistency of the test assertions have been retained.

field = AutoField(name="field_name")
assert gen_rand_int64 == field.default
# db_returning must be explicitly False because Spanner is handling ID generation client-side
assert getattr(field, "db_returning", True) is False

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.

medium

For consistency and clarity, it's better to access the db_returning attribute directly. The AutoField class defines this attribute, so it will always be present on the field instance. Using getattr with a default is unnecessary and makes the assertion slightly harder to read compared to a direct access.

Suggested change
assert getattr(field, "db_returning", True) is False
assert field.db_returning is False

assert gen_rand_int64 == field.default
# Since this specific connection explicitly enables client-side random generation,
# we must tell Django not to attempt retrieving the DB's returned ID.
assert getattr(field, "db_returning", True) is False

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.

medium

Similar to my other comment, direct attribute access is preferred here for better readability and consistency. Since db_returning is a standard attribute of AutoField, getattr is not needed.

Suggested change

@chalmerlowe chalmerlowe 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.

LGTM.

@olavloite olavloite merged commit 8c1eb13 into main Mar 16, 2026
51 of 56 checks passed
@olavloite olavloite deleted the issue-15930 branch March 16, 2026 15:05
ohmayr pushed a commit that referenced this pull request Mar 23, 2026
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v0.0.0-20260216162532-e323d455c92b
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:160860d189ff1c2f7515638478823712fa5b243e27ccc33a2728669fa1e2ed0c
<details><summary>django-google-spanner: v4.0.3</summary>

##
[v4.0.3](django-google-spanner-v4.0.2...django-google-spanner-v4.0.3)
(2026-03-23)

### Bug Fixes

* db_returning should only be overridden for Spanner (#16111)
([8c1eb13](8c1eb13f))

</details>


<details><summary>google-cloud-dataplex: v2.17.0</summary>

##
[v2.17.0](google-cloud-dataplex-v2.16.0...google-cloud-dataplex-v2.17.0)
(2026-03-23)

### Features

* add support for attaching aspects to EntryLinks (PiperOrigin-RevId:
883306841)
([ee7dd7d](ee7dd7dc))

* add DataProductService to manage data products and underlying data
assets (PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

* add LookupContext to CatalogService for LLM-generated resource context
(PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

* add debug query support to Data Quality rules (PiperOrigin-RevId:
883306841)
([ee7dd7d](ee7dd7dc))

* add UpdateEntryLink and LookupEntryLinks methods to CatalogService
(PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

* allow selective generation scope for Data Documentation scans
(PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

* support OneTime triggers for DataScan operations (PiperOrigin-RevId:
883306841)
([ee7dd7d](ee7dd7dc))

* add SKIPPED state to DataScan catalog publishing status
(PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

* add MetadataFeed to CatalogService for tracking metadata changes
(PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

### Bug Fixes

* remove deprecated Explore-related methods and messages from public
client libraries Breaking Changes: - Removed ContentService and all
associated methods (CreateContent, UpdateContent, DeleteContent,
GetContent, ListContent, etc.) and request/response messages. - Removed
Environment and Session management methods from DataplexService
(CreateEnvironment, UpdateEnvironment, DeleteEnvironment,
ListEnvironments, GetEnvironment, ListSessions) and their associated
messages. (PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

### Documentation

* remove deprecated metadata change warnings in Dataplex Catalog The
DataProductService provides APIs to curate and manage collections of
data assets as data products, enabling more organized sharing and usage
for specific business cases. MetadataFeeds allow users to monitor
metadata changes (CREATE, UPDATE, DELETE) within a specified scope
(organization, project, or entry group) and publish them to Pub/Sub.
CatalogService now includes a LookupContext API to provide LLM-generated
context for resources, and enhanced EntryLink management, including the
ability to attach aspects. DataScan operations now support a OneTime
trigger for single-run scans, and Data Quality rules support
DebugQueries to help investigate rule failures by returning diagnostic
values. (PiperOrigin-RevId: 883306841)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>google-cloud-documentai: v3.12.0</summary>

##
[v3.12.0](google-cloud-documentai-v3.11.0...google-cloud-documentai-v3.12.0)
(2026-03-23)

### Features

* Add a field for upgrading previous processor version when fine tuning
(PiperOrigin-RevId: 882129422)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>google-cloud-firestore: v2.26.0</summary>

##
[v2.26.0](google-cloud-firestore-v2.25.0...google-cloud-firestore-v2.26.0)
(2026-03-23)

### Features

* Add `Rand` and `Trunc` expressions (#16037)
([7538aa5](7538aa5d))

</details>


<details><summary>google-cloud-iap: v1.20.0</summary>

##
[v1.20.0](google-cloud-iap-v1.19.0...google-cloud-iap-v1.20.0)
(2026-03-23)

### Features

* add oauth fields for IapSettings (PiperOrigin-RevId: 883439941)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>google-cloud-network-connectivity: v2.14.0</summary>

##
[v2.14.0](google-cloud-network-connectivity-v2.13.0...google-cloud-network-connectivity-v2.14.0)
(2026-03-23)

### Features

* onboard a new library (PiperOrigin-RevId: 876282040)
([2647414](2647414d))

### Bug Fixes

* add warehouse package name to v1beta (PiperOrigin-RevId: 885295553)
([3701721](37017215))

</details>


<details><summary>google-cloud-securitycenter: v1.43.0</summary>

##
[v1.43.0](google-cloud-securitycenter-v1.42.0...google-cloud-securitycenter-v1.43.0)
(2026-03-23)

### Features

* Support Chokepoint and external exposure in findings Proto
(PiperOrigin-RevId: 884685891)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>google-cloud-vectorsearch: v0.8.0</summary>

##
[v0.8.0](google-cloud-vectorsearch-v0.7.0...google-cloud-vectorsearch-v0.8.0)
(2026-03-23)

### Features

* Add support for ExportDataObjects (PiperOrigin-RevId: 882214457)
([ee7dd7d](ee7dd7dc))

* Mark Vector Search v1 API as GA (PiperOrigin-RevId: 882214457)
([ee7dd7d](ee7dd7dc))

### Documentation

* Update changelog entry for release (#16092)
([1289664](12896643))

</details>


<details><summary>google-maps-navconnect: v0.1.0</summary>

##
[v0.1.0](google-maps-navconnect-v0.0.0...google-maps-navconnect-v0.1.0)
(2026-03-23)

### Features

* onboard a new library (PiperOrigin-RevId: 879267201)
([2158300](21583003))

</details>


<details><summary>google-shopping-css: v0.4.0</summary>

##
[v0.4.0](google-shopping-css-v0.3.0...google-shopping-css-v0.4.0)
(2026-03-23)

### Features

* add product rating fields to CSS API v1. This is in preparation for an
upcoming feature and the new fields are not yet used.
(PiperOrigin-RevId: 882470295)
([ee7dd7d](ee7dd7dc))

### Documentation

* A comment for field `name` in message
`.google.shopping.css.v1.GetCssProductRequest` is changed
(PiperOrigin-RevId: 882470295)
([ee7dd7d](ee7dd7dc))

* A comment for field `size_types` in message
`.google.shopping.css.v1.Attributes` is changed (PiperOrigin-RevId:
882470295)
([ee7dd7d](ee7dd7dc))

* A comment for field `name` in message
`.google.shopping.css.v1.CssProductInput` is changed (PiperOrigin-RevId:
882470295)
([ee7dd7d](ee7dd7dc))

* A comment for field `name` in message
`.google.shopping.css.v1.AccountLabel` is changed (PiperOrigin-RevId:
882470295)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>google-shopping-merchant-accounts: v1.4.0</summary>

##
[v1.4.0](google-shopping-merchant-accounts-v1.3.0...google-shopping-merchant-accounts-v1.4.0)
(2026-03-23)

### Features

* Add CreateTestAccount RPC to Accounts service for creating test-only
Merchant Center accounts (PiperOrigin-RevId: 884882604)
([75697a6](75697a6f))

### Documentation

* Improve TermsOfServiceKind.MERCHANT_CENTER comment (PiperOrigin-RevId:
884882604)
([75697a6](75697a6f))

* Update Region to support radius_area and clarify area type exclusivity
(PiperOrigin-RevId: 884882604)
([75697a6](75697a6f))

* Update Account.account_name documentation for naming restrictions
(PiperOrigin-RevId: 884882604)
([75697a6](75697a6f))

* Clarify CheckoutSettings.eligible_destinations usage
(PiperOrigin-RevId: 884882604)
([75697a6](75697a6f))

* Add product-ratings to Program documentation (PiperOrigin-RevId:
884882604)
([75697a6](75697a6f))

* Update DeleteUser method description (PiperOrigin-RevId: 884882604)
([75697a6](75697a6f))

* Refine DeveloperRegistration.developer_email behavior description
(PiperOrigin-RevId: 884882604)
([75697a6](75697a6f))

</details>


<details><summary>google-shopping-merchant-products: v1.4.0</summary>

##
[v1.4.0](google-shopping-merchant-products-v1.3.0...google-shopping-merchant-products-v1.4.0)
(2026-03-23)

### Features

* Added several fields to enhance shipping configurations: -
`handling_cutoff_time` and `handling_cutoff_timezone` within the
`Shipping` message - `ShippingBusinessDaysConfig` message to define
business days for shipping - `shipping_handling_business_days` and
`shipping_transit_business_days` in `ProductAttributes` -
`HandlingCutoffTime` message to configure country-specific handling
cutoffs - `handling_cutoff_times` array in `ProductAttributes`
(PiperOrigin-RevId: 830818193)
([ee7dd7d](ee7dd7dc))

* Added C#, PHP, and Ruby namespace options to ProductInputs, Products,
and ProductsCommon proto files for improved client library generation
(PiperOrigin-RevId: 830818171)
([ee7dd7d](ee7dd7dc))

* update products_common fields to include `handling_cutoff_timezone `,
`shipping_handling_business_days`, `shipping_transit_business_days`
(PiperOrigin-RevId: 881874426)
([ee7dd7d](ee7dd7dc))

* Added `handling_cutoff_time` and `handling_cutoff_timezone` fields to
the `Shipping` message within `Attributes` (PiperOrigin-RevId:
830818171)
([ee7dd7d](ee7dd7dc))

* Added the `product_id_base64_url_encoded` field to
`InsertProductInputRequest`, `DeleteProductInputRequest`, and
`GetProductRequest`. This allows for product IDs containing special
characters to be correctly handled when unpadded base64url-encoded
(PiperOrigin-RevId: 830818193)
([ee7dd7d](ee7dd7dc))

### Documentation

* Updated various comments, including links to data source creation
guides (PiperOrigin-RevId: 830818193)
([ee7dd7d](ee7dd7dc))

* Updated comments for several fields, including product name formats,
data source creation, destination field descriptions (now also referred
to as Marketing Methods), and the default page size for
`ListProductsRequest` (PiperOrigin-RevId: 830818171)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>grafeas: v1.21.0</summary>

##
[v1.21.0](grafeas-v1.20.0...grafeas-v1.21.0)
(2026-03-23)

### Features

* Added line_number to FileLocation (PiperOrigin-RevId: 882149723)
([ee7dd7d](ee7dd7dc))

</details>


<details><summary>sqlalchemy-spanner: v1.17.3</summary>

##
[v1.17.3](sqlalchemy-spanner-v1.17.2...sqlalchemy-spanner-v1.17.3)
(2026-03-23)

### Bug Fixes

* provide default sqlite db config for unit tests
([03cce70](03cce701))

* add missing docs and docfx sessions
([8fb857d](8fb857df))

* remove test_config generation from unit session
([9cc1f90](9cc1f90b))

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-increment ID from MySQL is not populated in model instance when Spanner is the default DB

3 participants