From: Federico Caselli Date: Wed, 9 Aug 2023 21:27:21 +0000 (+0200) Subject: Fix rendering of order in sequences and identity columns. X-Git-Tag: rel_2_0_21~35^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cf73b322a320c16b574a4d3d5e93a9dd3648321;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix rendering of order in sequences and identity columns. Fixes the rendering of the Oracle only ``order`` attribute in Sequence and Identity that was passed also when rendering the DDL in PostgreSQL. Fixes: #10207 Change-Id: I5b918eab38ba68fa10a213a79e2bd0cc48401a02 --- diff --git a/doc/build/changelog/unreleased_14/10207.rst b/doc/build/changelog/unreleased_14/10207.rst new file mode 100644 index 0000000000..aef31e6a42 --- /dev/null +++ b/doc/build/changelog/unreleased_14/10207.rst @@ -0,0 +1,12 @@ +.. change:: + :tags: schema, bug + :tickets: 10207 + :versions: 2.0.21 + + Modified the rendering of the Oracle only :paramref:`.Identity.order` + parameter that's part of both :class:`.Sequence` and :class:`.Identity` to + only take place for the Oracle backend, and not other backends such as that + of PostgreSQL. A future release will rename the + :paramref:`.Identity.order`, :paramref:`.Sequence.order` and + :paramref:`.Identity.on_null` parameters to Oracle-specific names, + deprecating the old names, these parameters only apply to Oracle. diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index 221599812a..4a3ac3ac07 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -1315,8 +1315,9 @@ class OracleDDLCompiler(compiler.DDLCompiler): text = text.replace("NO MINVALUE", "NOMINVALUE") text = text.replace("NO MAXVALUE", "NOMAXVALUE") text = text.replace("NO CYCLE", "NOCYCLE") - text = text.replace("NO ORDER", "NOORDER") - return text + if identity_options.order is not None: + text += " ORDER" if identity_options.order else " NOORDER" + return text.strip() def visit_computed_column(self, generated, **kw): text = "GENERATED ALWAYS AS (%s)" % self.sql_compiler.process( diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 2304bde754..314cbe2167 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -6688,8 +6688,6 @@ class DDLCompiler(Compiled): text.append("NO MAXVALUE") if identity_options.cache is not None: text.append("CACHE %d" % identity_options.cache) - if identity_options.order is not None: - text.append("ORDER" if identity_options.order else "NO ORDER") if identity_options.cycle is not None: text.append("CYCLE" if identity_options.cycle else "NO CYCLE") return " ".join(text) diff --git a/test/dialect/oracle/test_compiler.py b/test/dialect/oracle/test_compiler.py index 9b858c125e..c7a6858d4c 100644 --- a/test/dialect/oracle/test_compiler.py +++ b/test/dialect/oracle/test_compiler.py @@ -1581,7 +1581,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): schema.CreateTable(t), "CREATE TABLE t (y INTEGER GENERATED ALWAYS AS IDENTITY " "(INCREMENT BY 7 START WITH 4 NOMINVALUE NOMAXVALUE " - "NOORDER NOCYCLE))", + "NOCYCLE NOORDER))", ) def test_column_identity_no_generated(self): diff --git a/test/sql/test_identity_column.py b/test/sql/test_identity_column.py index 87d5e9f09f..2603a9e101 100644 --- a/test/sql/test_identity_column.py +++ b/test/sql/test_identity_column.py @@ -55,14 +55,10 @@ class _IdentityDDLFixture(testing.AssertsCompiledSQL): "ALWAYS AS IDENTITY (START WITH 1 MAXVALUE 10 CYCLE)", ), ( - dict(always=False, cache=1000, order=True), - "BY DEFAULT AS IDENTITY (CACHE 1000 ORDER)", - ), - (dict(order=True, cycle=True), "BY DEFAULT AS IDENTITY (ORDER CYCLE)"), - ( - dict(order=False, cycle=False), - "BY DEFAULT AS IDENTITY (NO ORDER NO CYCLE)", + dict(always=False, cache=1000, cycle=False), + "BY DEFAULT AS IDENTITY (CACHE 1000 NO CYCLE)", ), + (dict(cycle=True), "BY DEFAULT AS IDENTITY (CYCLE)"), ) def test_create_ddl(self, identity_args, text): if getattr( @@ -71,7 +67,6 @@ class _IdentityDDLFixture(testing.AssertsCompiledSQL): text = text.replace("NO MINVALUE", "NOMINVALUE") text = text.replace("NO MAXVALUE", "NOMAXVALUE") text = text.replace("NO CYCLE", "NOCYCLE") - text = text.replace("NO ORDER", "NOORDER") t = Table( "foo_table", @@ -169,7 +164,7 @@ class IdentityDDL(_IdentityDDLFixture, fixtures.TestBase): Column( "foo", Integer(), - Identity(always=False, on_null=True, start=42, order=True), + Identity(always=False, on_null=True, start=42, cycle=True), ), ) text = " ON NULL" if testing.against("oracle") else "" @@ -178,7 +173,7 @@ class IdentityDDL(_IdentityDDLFixture, fixtures.TestBase): ( "CREATE TABLE foo_table (foo INTEGER GENERATED BY DEFAULT" + text - + " AS IDENTITY (START WITH 42 ORDER))" + + " AS IDENTITY (START WITH 42 CYCLE))" ), ) @@ -266,7 +261,7 @@ class IdentityTest(fixtures.TestBase): assert_raises_message(ArgumentError, text, fn, server_onupdate="42") def test_to_metadata(self): - identity1 = Identity("by default", on_null=True, start=123) + identity1 = Identity("by default", cycle=True, start=123) m = MetaData() t = Table( "t", m, Column("x", Integer), Column("y", Integer, identity1) diff --git a/test/sql/test_sequences.py b/test/sql/test_sequences.py index f830d1c292..0781ff294c 100644 --- a/test/sql/test_sequences.py +++ b/test/sql/test_sequences.py @@ -57,10 +57,9 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL): "START WITH 1 MAXVALUE 10 CYCLE", ), ( - Sequence("foo_seq", cache=1000, order=True), - "CACHE 1000 ORDER", + Sequence("foo_seq", cache=1000), + "CACHE 1000", ), - (Sequence("foo_seq", order=True), "ORDER"), (Sequence("foo_seq", minvalue=42), "MINVALUE 42"), (Sequence("foo_seq", minvalue=-42), "MINVALUE -42"), ( @@ -75,6 +74,12 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL): Sequence("foo_seq", minvalue=42, increment=-2), "INCREMENT BY -2 MINVALUE 42", ), + ( + # remove this when the `order` parameter is removed + # issue #10207 - ensure ORDER does not render + Sequence("foo_seq", order=True), + "", + ), ( Sequence("foo_seq", minvalue=-42, increment=-2), "INCREMENT BY -2 MINVALUE -42",