]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- alter behavior such that dialect_kwargs is still immutable, but
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Jan 2014 21:32:36 +0000 (16:32 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Jan 2014 21:32:36 +0000 (16:32 -0500)
now represents exactly the kwargs that were passed, and not the defaults.
the defaults are still in dialect_options.  This allows repr() schemes such as that
of alembic to not need to look through and compare for defaults.

lib/sqlalchemy/sql/base.py
test/sql/test_metadata.py

index f4bfe392a86a634bdd1646034c86542fbcaf2d5a..4a7dd65d3f4a5bdfb96aaf37f2b7329371b357d7 100644 (file)
@@ -56,7 +56,9 @@ class DialectKWArgs(object):
         options to this construct.
 
         The arguments are present here in their original ``<dialect>_<kwarg>``
-        format.
+        format.  Only arguments that were actually passed are included;
+        unlike the :attr:`.DialectKWArgs.dialect_options` collection, which
+        contains all options known by this dialect including defaults.
 
         .. versionadded:: 0.9.2
 
@@ -66,14 +68,7 @@ class DialectKWArgs(object):
 
         """
 
-        return util.immutabledict(
-            (
-                "%s_%s" % (dialect_name, kwarg_name),
-                kw_dict[kwarg_name]
-            )
-            for dialect_name, kw_dict in self.dialect_options.items()
-            for kwarg_name in kw_dict if kwarg_name != '*'
-        )
+        return util.immutabledict()
 
     @property
     def kwargs(self):
@@ -128,7 +123,7 @@ class DialectKWArgs(object):
         if not kwargs:
             return
 
-        self.__dict__.pop('dialect_kwargs', None)
+        self.dialect_kwargs = self.dialect_kwargs.union(kwargs)
 
         for k in kwargs:
             m = re.match('^(.+?)_(.+)$', k)
index 91a5a26004417f198403bb8602cd1c995f5fc23c..2a52428ddbe963c150ca56126350e3b4e7ddaedc 100644 (file)
@@ -2088,12 +2088,14 @@ class DialectKWArgTest(fixtures.TestBase):
     def test_participating(self):
         with self._fixture():
             idx = Index('a', 'b', 'c', participating_y=True)
+            eq_(
+                idx.dialect_options,
+                {"participating": {"x": 5, "y": True, "z_one": None}}
+            )
             eq_(
                 idx.dialect_kwargs,
                 {
-                    'participating_z_one': None,
                     'participating_y': True,
-                    'participating_x': 5
                 }
             )
 
@@ -2150,21 +2152,35 @@ class DialectKWArgTest(fixtures.TestBase):
         with self._fixture():
             idx = Index('a', 'b', 'c', unknown_y=True, unknown_z=5,
                                 otherunknown_foo='bar', participating_y=8)
+            eq_(
+                idx.dialect_options,
+                {
+                    "unknown": {'y': True, 'z': 5, '*': None},
+                    "otherunknown": {'foo': 'bar', '*': None},
+                    "participating": {'x': 5, 'y': 8, 'z_one': None}
+                }
+            )
             eq_(idx.dialect_kwargs,
                 {'unknown_z': 5, 'participating_y': 8,
-                'unknown_y': True, 'participating_z_one': None,
-                'otherunknown_foo': 'bar', 'participating_x': 5}
+                'unknown_y': True,
+                'otherunknown_foo': 'bar'}
             )  # still populates
 
     def test_combined(self):
         with self._fixture():
             idx = Index('a', 'b', 'c', participating_x=7,
                                     nonparticipating_y=True)
+
+            eq_(
+                idx.dialect_options,
+                {
+                    'participating': {'y': False, 'x': 7, 'z_one': None},
+                    'nonparticipating': {'y': True, '*': None}
+                }
+            )
             eq_(
                 idx.dialect_kwargs,
                 {
-                    'participating_z_one': None,
-                    'participating_y': False,
                     'participating_x': 7,
                     'nonparticipating_y': True,
                 }
@@ -2177,13 +2193,17 @@ class DialectKWArgTest(fixtures.TestBase):
                         participating2_x=15,
                         participating2_y="lazy"
                 )
+            eq_(
+                idx.dialect_options,
+                {
+                    "participating": {'x': 7, 'y': False, 'z_one': None},
+                    "participating2": {'x': 15, 'y': 'lazy', 'pp': 'default'},
+                }
+            )
             eq_(
                 idx.dialect_kwargs,
                 {
-                    'participating_z_one': None,
                     'participating_x': 7,
-                    'participating_y': False,
-                    'participating2_pp': 'default',
                     'participating2_x': 15,
                     'participating2_y': 'lazy'
                 }
@@ -2257,29 +2277,39 @@ class DialectKWArgTest(fixtures.TestBase):
             idx = Index('a', 'b', 'c', participating_x=20)
             eq_(idx.dialect_kwargs, {
                         "participating_x": 20,
-                        'participating_z_one': None,
-                        "participating_y": False})
+                    })
             idx._validate_dialect_kwargs({
                         "participating_x": 25,
                         "participating_z_one": "default"})
+            eq_(idx.dialect_options, {
+                    "participating": {"x": 25, "y": False, "z_one": "default"}
+                    })
             eq_(idx.dialect_kwargs, {
                         "participating_x": 25,
-                        'participating_z_one': "default",
-                        "participating_y": False})
+                        'participating_z_one': "default"
+                    })
+
             idx._validate_dialect_kwargs({
                         "participating_x": 25,
                         "participating_z_one": "default"})
+
+            eq_(idx.dialect_options, {
+                    "participating": {"x": 25, "y": False, "z_one": "default"}
+                    })
             eq_(idx.dialect_kwargs, {
-                        'participating_z_one': 'default',
-                        'participating_y': False,
-                        'participating_x': 25})
+                        "participating_x": 25,
+                        'participating_z_one': "default"
+                    })
+
             idx._validate_dialect_kwargs({
                         "participating_y": True,
                         'participating2_y': "p2y"})
+            eq_(idx.dialect_options, {
+                    "participating": {"x": 25, "y": True, "z_one": "default"},
+                    "participating2": {"y": "p2y", "pp": "default", "x": 9}
+                    })
             eq_(idx.dialect_kwargs, {
                         "participating_x": 25,
-                        "participating2_x": 9,
                         "participating_y": True,
                         'participating2_y': "p2y",
-                        "participating2_pp": "default",
                         "participating_z_one": "default"})