From 273f03bdf27c12317712a9939eedd25bd88c475a Mon Sep 17 00:00:00 2001 From: minev-dev <90937832+minev-dev@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:04:15 -0800 Subject: [PATCH] fix: Add `existing_nullable` usage to `visit_column_type` (#329) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Add `existing_nullable` usage to `visit_column_type` Without this, altering operations (e.g. change column length) can cause nullability change of the column. It then causes error if this column is a part of index: "400 Changing NOT NULL constraints on column column_name is not allowed because it affects index index_name" * fix: add missing placeholder --------- Co-authored-by: Knut Olav Løite --- google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py b/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py index 6754931a..1514f9e3 100644 --- a/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py +++ b/google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py @@ -1564,8 +1564,9 @@ def visit_column_nullable( def visit_column_type( element: "ColumnType", compiler: "SpannerDDLCompiler", **kw ) -> str: - return "%s %s %s" % ( + return "%s %s %s %s" % ( alter_table(compiler, element.table_name, element.schema), alter_column(compiler, element.column_name), "%s" % format_type(compiler, element.type_), + "" if element.existing_nullable else "NOT NULL", )