From: Mike Bayer Date: Sun, 19 Jan 2014 21:32:36 +0000 (-0500) Subject: - alter behavior such that dialect_kwargs is still immutable, but X-Git-Tag: rel_0_9_2~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3dc9f9b3db10254f688c6b25b58951a4b1d4a41b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - alter behavior such that dialect_kwargs is still immutable, but 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. --- diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index f4bfe392a8..4a7dd65d3f 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -56,7 +56,9 @@ class DialectKWArgs(object): options to this construct. The arguments are present here in their original ``_`` - 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) diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 91a5a26004..2a52428ddb 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -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"})