]> 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:18:02 +0000 (11:18 -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
(cherry picked from commit 5615ab52c81e2343330069f91ec3544840519956)

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 6e72ebe8b5b36a04232d7699bf9c687ba37b9226..2e49b202c6da4ee00fad1a4e48d6c28ed1046815 100644 (file)
@@ -1381,8 +1381,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):
         text = "GENERATED ALWAYS AS (%s)" % self.sql_compiler.process(
index 0a460b8c091321e1153f3ae7ebd052327279e74a..e72e2f8c045d11cea54d408060c8c0771e7bb790 100644 (file)
@@ -4790,8 +4790,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 6c3e0fb706b69e1b6808534cfa95f47cb5cdb30b..737c11f46801247c50f9506935a214c638662da7 100644 (file)
@@ -1373,7 +1373,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 00404dae791b59c2c8384188aebab96caca76f6e..a93c5e6c507c1a34fe45f1c46e870e0c8cc7c4fc 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):
 
@@ -72,7 +68,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",
@@ -170,7 +165,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 ""
@@ -179,7 +174,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))"
             ),
         )
 
@@ -268,7 +263,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 a0fef99be31af8f56a8525e301d0862d6beb7d6f..5766b724e54b39fd945ad3267a7b38d825acbc8b 100644 (file)
@@ -84,13 +84,21 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
         )
 
         self.assert_compile(
-            CreateSequence(Sequence("foo_seq", cache=1000, order=True)),
-            "CREATE SEQUENCE foo_seq START WITH 1 CACHE 1000 ORDER",
+            CreateSequence(Sequence("foo_seq", cache=1000)),
+            "CREATE SEQUENCE foo_seq START WITH 1 CACHE 1000",
         )
 
+        # remove this when the `order` parameter is removed
+        # issue #10207 - ensure ORDER does not render
+        self.assert_compile(
+            CreateSequence(Sequence("foo_seq", order=True)),
+            "CREATE SEQUENCE foo_seq START WITH 1",
+        )
+        # only renders for Oracle
         self.assert_compile(
             CreateSequence(Sequence("foo_seq", order=True)),
             "CREATE SEQUENCE foo_seq START WITH 1 ORDER",
+            dialect="oracle",
         )
 
         self.assert_compile(