You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(django-google-spanner): support Django 6.0 (#18128)
## Description
This PR adds support for **Django 6.0** in `django-google-spanner` while
maintaining full backwards compatibility with **Django 5.2**.
Fixes#18053
---
### Key Changes
- **Covering Indexes (`STORING`)**: Added support for `include` clauses
in index creation, generating Cloud Spanner GoogleSQL `STORING (col1,
col2)` DDL; declared `supports_covering_indexes = True`.
- **Composite Primary Keys**: Declared support for Django 6.0 composite
primary keys (`supports_composite_primary_keys = True`).
- **DML Returning Clauses**: Enabled `can_return_columns_from_insert =
True` and updated `returning_columns()` in `operations.py` to safely
handle column names and expression objects, allowing Django to
automatically populate database defaults and `GeneratedField` values on
`INSERT ... THEN RETURN`.
---
### Behavioral Notes for Users
- **DML `THEN RETURN`**: With `can_return_columns_from_insert = True`,
Django will now generate `THEN RETURN` clauses for models with
database-generated defaults or `GeneratedField` columns upon `.save()`.
Applications wishing to preserve legacy behavior can opt out via
`AppConfig`:
```python
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = "myapp"
def ready(self):
from django_spanner.features import DatabaseFeatures
DatabaseFeatures.can_return_columns_from_insert = False
Thank you for opening a Pull Request! Before submitting your PR, there
are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a
[bug/issue](https://github.com/googleapis/google-cloud-python/issues)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
Fixes#18053 🦕
@@ -266,6 +267,26 @@ By participating in this project you agree to abide by its terms. See the `Code
266
267
of Conduct <https://github.com/googleapis/google-cloud-python/blob/main/CODE_OF_CONDUCT.md>`_ for more information.
267
268
268
269
270
+
DML RETURNING Behavior
271
+
~~~~~~~~~~~~~~~~~~~~~~
272
+
273
+
Starting with Django 6.0 compatibility, ``can_return_columns_from_insert = True`` is enabled. Django will generate ``THEN RETURN`` clauses for insert statements that create model instances with database-generated defaults or ``GeneratedField`` columns.
274
+
275
+
If your application relies on the previous behavior (where returned columns were not queried automatically upon insert), you can disable it in your Django ``AppConfig``:
276
+
277
+
.. code:: python
278
+
279
+
from django.apps import AppConfig
280
+
281
+
classMyAppConfig(AppConfig):
282
+
name ="myapp"
283
+
284
+
defready(self):
285
+
from django_spanner.features import DatabaseFeatures
0 commit comments