feat(django-google-spanner): support Django 6.0 - #18128
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for Django 6.0, including dependency updates, tuple-casting for lookup parameters, an asynchronous autocommit setter, and a Spanner-specific JSON path compiler. The review feedback highlights critical improvements: resolving syntax, type, and SQL injection issues in compile_json_path by utilizing json.dumps; wrapping the async autocommit operation in self.execute_wrapper to align with Django standards; and fixing invalid shell syntax and compatibility issues in the new test suite script.
311d5d1 to
cfa5943
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for Django 6.0 in the django-google-spanner package. Key changes include updating supported versions and dependencies, implementing async autocommit handling, adding Django 6.0 test exclusions, and updating database features, operations, and schema editors to support index inclusion columns and returning columns from inserts. Feedback on these changes highlights two important issues: first, the _index_include_sql helper in schema.py should resolve actual database column names via model._meta.get_field(field).column rather than using str(field) directly; second, the async autocommit wrapper in base.py should use thread_sensitive=True with sync_to_async to ensure thread safety and prevent connection sharing issues.
cfa5943 to
b219da1
Compare
…d lookups parameter indexing
| "sqlparse >= 0.3.0", | ||
| "google-cloud-spanner >= 3.13.0", | ||
| "django >= 5.2, < 6.0", | ||
| "google-cloud-spanner >= 3.69.1", |
There was a problem hiding this comment.
Please can you clarify if we really need to bump google-cloud-spanner? Do tests fail with 3.13.0?
Is there a lower minimum that we can set here?
If 3.69.1 is yanked or has a regression, users may not be able to install/use the latest version of django-google-spanner
https://pypi.org/project/google-cloud-spanner/3.69.1/
There was a problem hiding this comment.
#18152 This fix is needed for can_return_columns_from_insert to work correctly. I will update this version to 3.69.2 once we have a new version released. I am planning to push this change to 3.70.0 or 3.69.3
…nd docs for Django 6.0
| UNIT_TEST_DEPENDENCIES = [ | ||
| "django~=5.2", | ||
| "sqlparse==0.3.1", | ||
| "django>=5.2,<6.1", | ||
| "sqlparse>=0.3.1", | ||
| ] | ||
|
|
||
| UNIT_TEST_MOCKSERVER_DEPENDENCIES = [ | ||
| "django~=5.2", | ||
| "google-cloud-spanner>=3.55.0", | ||
| "django>=5.2,<6.1", | ||
| "google-cloud-spanner>=3.69.1", | ||
| "sqlparse>=0.4.4", | ||
| ] |
There was a problem hiding this comment.
This only expands the allowed versions, it does not ensure that we actually run the tests for both supported Django versions. We should probably use something like nox.parameterize to ensure that we really run the tests for both versions that we support, so something like this:
DJANGO_VERSIONS = ["5.2", "6.0"]
def default(session, django_version="5.2"):
# Target specific Django version
django_dep = f"django~={django_version}.0" if django_version == "6.0" else "django~=5.2.0"
session.install(
*UNIT_TEST_STANDARD_DEPENDENCIES,
*UNIT_TEST_EXTERNAL_DEPENDENCIES,
*UNIT_TEST_MOCKSERVER_DEPENDENCIES,
django_dep,
)
session.install("-e", ".")
# Run py.test against unit and mockserver tests.
session.run(
"py.test",
"--quiet",
"--cov=django_spanner",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
os.path.join("tests", "mockserver_tests"),
*session.posargs,
)
@nox.session(python=ALL_PYTHON)
@nox.parametrize("django", DJANGO_VERSIONS)
def unit(session, django):
"""Run the unit test suite across Django versions."""
default(session, django_version=django)
@nox.session(python=MOCKSERVER_TEST_PYTHON_VERSION)
@nox.parametrize("django", DJANGO_VERSIONS)
def mockserver(session, django):
"""Run mockserver tests across Django versions."""
default(session, django_version=django)
We should also check the GitHub Actions workflows to ensure that:
- They actually run the right
noxsessions so they test both versions (I think they do) - They use Python versions that support both versions that we support (django-spanner-integration-tests-against-emulator-3.10.yml probably does not). Alternatively: Add a matrix to these workflows to test with multiple Python versions to ensure that the behavior is correct in those cases as well.
olavloite
left a comment
There was a problem hiding this comment.
These changes LGTM, but please fix the problem that the tests are not actually running for both versions before merging (and of course ensure that the tests pass for both versions).
Description
This PR adds support for Django 6.0 in
django-google-spannerwhile maintaining full backwards compatibility with Django 5.2.Fixes #18053
Key Changes
STORING): Added support forincludeclauses in index creation, generating Cloud Spanner GoogleSQLSTORING (col1, col2)DDL; declaredsupports_covering_indexes = True.supports_composite_primary_keys = True).can_return_columns_from_insert = Trueand updatedreturning_columns()inoperations.pyto safely handle column names and expression objects, allowing Django to automatically populate database defaults andGeneratedFieldvalues onINSERT ... THEN RETURN.Behavioral Notes for Users
THEN RETURN: Withcan_return_columns_from_insert = True, Django will now generateTHEN RETURNclauses for models with database-generated defaults orGeneratedFieldcolumns upon.save(). Applications wishing to preserve legacy behavior can opt out viaAppConfig: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:
Fixes #18053 🦕