]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix rendering of order in sequences and identity columns.
authorFederico Caselli <cfederico87@gmail.com>
Wed, 9 Aug 2023 21:27:21 +0000 (23:27 +0200)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 17 Aug 2023 15:20:22 +0000 (11:20 -0400)
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

doc/build/changelog/unreleased_14/10207.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/sql/compiler.py
test/dialect/oracle/test_compiler.py
test/sql/test_identity_column.py
test/sql/test_sequences.py

diff --git a/doc/build/changelog/unreleased_14/10207.rst b/doc/build/changelog/unreleased_14/10207.rst
new file mode 100644 (file)
index 0000000..aef31e6
--- /dev/null
@@ -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.
index 221599812ae9338a8524669fc45c625e8e6623e0..4a3ac3ac0781d91a1b8ddb3082cf90cd69abb2dc 100644 (file)
@@ -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(
index 2304bde7542482358794990a26fd98aed165ede9..314cbe2167d31b35e47685f4a39006c0a45adc06 100644 (file)
@@ -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)
index 9b858c125ee898e76d8f268cf3450ce2700eed5e..c7a6858d4cbfc1305e2971e14c4885eebd009fae 100644 (file)
@@ -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):
index 87d5e9f09f09bbfe4b734262bdabad7fcf8c9574..2603a9e1012f7d43a8b3476c8e0cb7d52e7db7e6 100644 (file)
@@ -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)
index f830d1c292c1d384646040b317df08076e6e40ac..0781ff294c8599639739307062c6cc4337467c81 100644 (file)
@@ -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",